From 07224cc7d5a76493574eef4a57661dc57c1cbe32 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Wed, 24 Jun 2020 16:28:35 +0300 Subject: [PATCH 01/20] Added Enchantment Rune. Added Enchantment Rune that applies a random enchantment on items. Works similar to Soulbound Rune. --- .../implementation/SlimefunItems.java | 2 + .../items/magical/EnchantmentRune.java | 171 ++++++++++++++++++ .../implementation/setup/ResearchSetup.java | 2 + .../setup/SlimefunItemSetup.java | 9 + src/main/resources/languages/messages_en.yml | 4 + .../resources/languages/researches_en.yml | 4 +- 6 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java index 6131fd18a..964e7161a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java @@ -327,6 +327,7 @@ public final class SlimefunItems { public static final SlimefunItemStack ENDER_LUMP_2 = new SlimefunItemStack("ENDER_LUMP_2", Material.GOLD_NUGGET, "&5Ender Lump &7- &eII", "", "&c&oTier: II"); public static final SlimefunItemStack ENDER_LUMP_3 = new SlimefunItemStack("ENDER_LUMP_3", Material.GOLD_NUGGET, "&5Ender Lump &7- &eIII", "", "&c&oTier: III"); public static final SlimefunItemStack MAGICAL_BOOK_COVER = new SlimefunItemStack("MAGICAL_BOOK_COVER", Material.PAPER, "&6Magical Book Cover", "", "&a&oUsed for various Magic Books"); + public static final SlimefunItemStack MAGICAL_GLASS = new SlimefunItemStack("MAGICAL_GLASS", Material.GLASS_PANE, "&6Magical Glass", "", "&a&oUsed for various Magical Gadgets"); public static final SlimefunItemStack MAGIC_PILLS = new SlimefunItemStack("MAGIC_PILLS", Material.NETHER_WART, "&cMagic Pills", "", "&a&oUsed to cure zombie villagers instantly"); public static final SlimefunItemStack BASIC_CIRCUIT_BOARD = new SlimefunItemStack("BASIC_CIRCUIT_BOARD", Material.ACTIVATOR_RAIL, "&bBasic Circuit Board"); public static final SlimefunItemStack ADVANCED_CIRCUIT_BOARD = new SlimefunItemStack("ADVANCED_CIRCUIT_BOARD", Material.POWERED_RAIL, "&bAdvanced Circuit Board"); @@ -599,6 +600,7 @@ public final class SlimefunItems { public static final SlimefunItemStack RAINBOW_RUNE = new SlimefunItemStack("ANCIENT_RUNE_RAINBOW", new ColoredFireworkStar(Color.FUCHSIA, "&7Ancient Rune &8&l[&d&lRainbow&8&l]")); public static final SlimefunItemStack LIGHTNING_RUNE = new SlimefunItemStack("ANCIENT_RUNE_LIGHTNING", new ColoredFireworkStar(Color.fromRGB(255, 255, 95), "&7Ancient Rune &8&l[&e&lLightning&8&l]")); public static final SlimefunItemStack SOULBOUND_RUNE = new SlimefunItemStack("ANCIENT_RUNE_SOULBOUND", new ColoredFireworkStar(Color.fromRGB(47, 0, 117), "&7Ancient Rune &8&l[&5&lSoulbound&8&l]", "&eDrop this rune onto a dropped item to", "&5bind ðat item to your soul.", " ", "&eIt is advised that you only use this rune", "&eon &6important &eitems.", " ", "&eItems bound to your soul won't drop on death.")); + public static final SlimefunItemStack ENCHANTMENT_RUNE = new SlimefunItemStack("ANCIENT_RUNE_ENCHANTMENT", new ColoredFireworkStar(Color.fromRGB(255, 217, 25), "&7Ancient Rune &8&l[&6&lEnchantment&8&l]", "&eDrop this rune onto a dropped item to", "&6enchant ðat item with a random enchantment.")); /* Electricity */ public static final SlimefunItemStack SOLAR_GENERATOR = new SlimefunItemStack("SOLAR_GENERATOR", Material.DAYLIGHT_DETECTOR, "&bSolar Generator", "", LoreBuilder.machine(MachineTier.BASIC, MachineType.GENERATOR), LoreBuilder.powerBuffer(0), LoreBuilder.powerPerSecond(4)); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java new file mode 100644 index 000000000..83a46b521 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java @@ -0,0 +1,171 @@ +package io.github.thebusybiscuit.slimefun4.implementation.items.magical; + +import java.util.Collection; +import java.util.Optional; +import java.util.concurrent.ThreadLocalRandom; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.inventory.ItemStack; + +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.handlers.ItemDropHandler; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; +import me.mrCookieSlime.Slimefun.api.Slimefun; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; + +/** + * This {@link SlimefunItem} allows you to enchant any enchantable {@link ItemStack} with a random + * {@link Enchantment}. It is also one of the very few utilisations of {@link ItemDropHandler}. + * + * @author Linox + * + * @see ItemDropHandler + * @see Enchantment + * + */ +public class EnchantmentRune extends SimpleSlimefunItem { + + private static final double RANGE = 1.5; + + private static final Enchantment[] helmEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.OXYGEN, Enchantment.WATER_WORKER, Enchantment.THORNS, Enchantment.PROTECTION_PROJECTILE, Enchantment.PROTECTION_FIRE, Enchantment.PROTECTION_ENVIRONMENTAL, Enchantment.PROTECTION_EXPLOSIONS}; + private static final Enchantment[] chestLeggingsEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.THORNS, Enchantment.PROTECTION_PROJECTILE, Enchantment.PROTECTION_FIRE, Enchantment.PROTECTION_ENVIRONMENTAL, Enchantment.PROTECTION_EXPLOSIONS}; + private static final Enchantment[] bootsEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.FROST_WALKER, Enchantment.PROTECTION_FALL, Enchantment.DEPTH_STRIDER, Enchantment.THORNS, Enchantment.PROTECTION_PROJECTILE, Enchantment.PROTECTION_FIRE, Enchantment.PROTECTION_ENVIRONMENTAL, Enchantment.PROTECTION_EXPLOSIONS}; + + private static final Enchantment[] swordEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.FIRE_ASPECT, Enchantment.LOOT_BONUS_MOBS, Enchantment.KNOCKBACK, Enchantment.SWEEPING_EDGE, Enchantment.DAMAGE_ALL, Enchantment.DAMAGE_ARTHROPODS, Enchantment.DAMAGE_UNDEAD}; + private static final Enchantment[] tridentEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.IMPALING, Enchantment.CHANNELING, Enchantment.LOYALTY, Enchantment.RIPTIDE}; + private static Enchantment[] crossbowEnch; + private static final Enchantment[] bowEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.ARROW_DAMAGE, Enchantment.ARROW_FIRE, Enchantment.ARROW_INFINITE, Enchantment.ARROW_KNOCKBACK}; + + private static final Enchantment[] axeEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.DIG_SPEED, Enchantment.LOOT_BONUS_BLOCKS, Enchantment.SILK_TOUCH, Enchantment.DAMAGE_ALL, Enchantment.DAMAGE_UNDEAD, Enchantment.DAMAGE_ARTHROPODS}; + private static final Enchantment[] toolEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.DIG_SPEED, Enchantment.LOOT_BONUS_BLOCKS, Enchantment.SILK_TOUCH}; + private static final Enchantment[] shearEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.DIG_SPEED}; + private static final Enchantment[] fishRodEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.LURE, Enchantment.LUCK}; + private static final Enchantment[] otherItemsEnch = {Enchantment.MENDING, Enchantment.DURABILITY}; + + public EnchantmentRune(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { + super(category, item, recipeType, recipe); + } + + @Override + public void preRegister() { + if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14)) { + crossbowEnch = new Enchantment[] {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.MULTISHOT, Enchantment.QUICK_CHARGE, Enchantment.PIERCING}; + } else { + crossbowEnch = null; + } + super.preRegister(); + } + + @Override + public ItemDropHandler getItemHandler() { + return (e, p, item) -> { + if (isItem(item.getItemStack())) { + + if (!Slimefun.hasUnlocked(p, SlimefunItems.ENCHANTMENT_RUNE, true)) { + return true; + } + + Slimefun.runSync(() -> activate(p, e, item), 20L); + + return true; + } + return false; + }; + } + + private void activate(Player p, PlayerDropItemEvent e, Item item) { + // Being sure the entity is still valid and not picked up or whatsoever. + if (!item.isValid()) { + return; + } + + Location l = item.getLocation(); + Collection entites = l.getWorld().getNearbyEntities(l, RANGE, RANGE, RANGE, this::findCompatibleItem); + Optional optional = entites.stream().findFirst(); + + if (optional.isPresent()) { + Item entity = (Item) optional.get(); + ItemStack target = entity.getItemStack(); + + Enchantment[] enchArr = findEnchArr(target.getType()); + if (enchArr.length == 0) return; + int enchIndex = ThreadLocalRandom.current().nextInt(enchArr.length); + Enchantment ench = enchArr[enchIndex]; + + int level = 1; + if (ench.getMaxLevel() != 1) level = ThreadLocalRandom.current().nextInt(ench.getMaxLevel() + 1); + + target.addEnchantment(ench, level); + + if (target.getAmount() == 1) { + e.setCancelled(true); + + // This lightning is just an effect, it deals no damage. + l.getWorld().strikeLightningEffect(l); + + Slimefun.runSync(() -> { + // Being sure entities are still valid and not picked up or whatsoever. + if (item.isValid() && entity.isValid() && target.getAmount() == 1) { + + l.getWorld().createExplosion(l, 0); + l.getWorld().playSound(l, Sound.ENTITY_GENERIC_EXPLODE, 0.3F, 1); + + entity.remove(); + item.remove(); + l.getWorld().dropItemNaturally(l, target); + + SlimefunPlugin.getLocal().sendMessage(p, "messages.enchantment-rune.success", true); + } + }, 10L); + } + else { + SlimefunPlugin.getLocal().sendMessage(p, "messages.enchantment-rune.fail", true); + } + } + } + + private Enchantment[] findEnchArr(Material type) { + Enchantment[] enchArr = null; + + if (type.name().endsWith("_HELMET")) enchArr = helmEnch; + if (type.name().endsWith("_CHESTPLATE") || type.name().endsWith("_LEGGINGS")) enchArr = chestLeggingsEnch; + if (type.name().endsWith("_BOOTS")) enchArr = bootsEnch; + if (type.name().endsWith("_SWORD")) enchArr = swordEnch; + if (type.name().endsWith("_AXE")) enchArr = axeEnch; + if (type.name().endsWith("_PICKAXE") || type.name().endsWith("_SHOVEL") || type.name().endsWith("_HOE")) enchArr = toolEnch; + + if (type == Material.TRIDENT) enchArr = tridentEnch; + if (type == Material.BOW) enchArr = bowEnch; + if (type == Material.SHEARS) enchArr = shearEnch; + if (type == Material.FISHING_ROD) enchArr = fishRodEnch; + if (crossbowEnch != null && type.name().equals("CROSSBOW")) enchArr = crossbowEnch; + + if (type == Material.SHIELD || type == Material.ELYTRA || type == Material.CARROT_ON_A_STICK || type == Material.FLINT_AND_STEEL) enchArr = otherItemsEnch; + + if (enchArr == null) enchArr = new Enchantment[0]; + return enchArr; + } + + private boolean findCompatibleItem(Entity n) { + if (n instanceof Item) { + Item item = (Item) n; + + return !isItem(item.getItemStack()); + } + + return false; + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java index a35f46fdb..1040ce3b6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java @@ -266,6 +266,8 @@ public final class ResearchSetup { register("industrial_miner", 95, "Industrial Mining", 28, SlimefunItems.INDUSTRIAL_MINER); register("advanced_industrial_miner", 98, "Better Mining", 36, SlimefunItems.ADVANCED_INDUSTRIAL_MINER); register("magic_pills", 257, "De-Zombification", 22, SlimefunItems.MAGIC_PILLS); + register("enchantment_rune", 258, "Ancient Enchanting", 24, SlimefunItems.ENCHANTMENT_RUNE); + register("magical_glass", 259, "Magical See-Through", 5, SlimefunItems.MAGICAL_GLASS); } private static void register(String key, int id, String name, int defaultCost, ItemStack... items) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index 1579b5dc5..35d650778 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -3,6 +3,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.setup; import java.util.ArrayList; import java.util.List; +import io.github.thebusybiscuit.slimefun4.implementation.items.magical.EnchantmentRune; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; @@ -372,6 +373,10 @@ public final class SlimefunItemSetup { new ItemStack[] {null, SlimefunItems.MAGIC_LUMP_2, null, SlimefunItems.MAGIC_LUMP_2, new ItemStack(Material.BOOK), SlimefunItems.MAGIC_LUMP_2, null, SlimefunItems.MAGIC_LUMP_2, null}) .register(plugin); + new SlimefunItem(categories.magicalResources, SlimefunItems.MAGICAL_GLASS, RecipeType.MAGIC_WORKBENCH, + new ItemStack[] {SlimefunItems.MAGIC_LUMP_2, SlimefunItems.GOLD_DUST, SlimefunItems.MAGIC_LUMP_2, SlimefunItems.FILLED_FLASK_OF_KNOWLEDGE, new ItemStack(Material.GLASS_PANE), SlimefunItems.FILLED_FLASK_OF_KNOWLEDGE, SlimefunItems.MAGIC_LUMP_2, SlimefunItems.FILLED_FLASK_OF_KNOWLEDGE, SlimefunItems.MAGIC_LUMP_2}) + .register(plugin); + new BasicCircuitBoard(categories.technicalComponents, SlimefunItems.BASIC_CIRCUIT_BOARD, RecipeType.MOB_DROP, new ItemStack[] {null, null, null, null, new CustomItem(SlimefunUtils.getCustomHead("89091d79ea0f59ef7ef94d7bba6e5f17f2f7d4572c44f90f76c4819a714"), "&aIron Golem"), null, null, null, null}) .register(plugin); @@ -2456,6 +2461,10 @@ public final class SlimefunItemSetup { new ItemStack[] {SlimefunItems.MAGIC_LUMP_3, SlimefunItems.ESSENCE_OF_AFTERLIFE, SlimefunItems.MAGIC_LUMP_3, SlimefunItems.ENDER_LUMP_3, SlimefunItems.ENDER_RUNE, SlimefunItems.ENDER_LUMP_3, SlimefunItems.MAGIC_LUMP_3, SlimefunItems.ESSENCE_OF_AFTERLIFE, SlimefunItems.MAGIC_LUMP_3}) .register(plugin); + new EnchantmentRune(categories.magicalResources, SlimefunItems.ENCHANTMENT_RUNE, RecipeType.ANCIENT_ALTAR, + new ItemStack[] {SlimefunItems.MAGIC_LUMP_3, SlimefunItems.MAGICAL_GLASS, SlimefunItems.MAGIC_LUMP_3, SlimefunItems.MAGICAL_GLASS, SlimefunItems.LIGHTNING_RUNE, SlimefunItems.MAGICAL_GLASS, SlimefunItems.MAGIC_LUMP_3, SlimefunItems.MAGICAL_GLASS, SlimefunItems.MAGIC_LUMP_3}) + .register(plugin); + new InfernalBonemeal(categories.magicalGadgets, SlimefunItems.INFERNAL_BONEMEAL, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.NETHER_WART), SlimefunItems.EARTH_RUNE, new ItemStack(Material.NETHER_WART), SlimefunItems.MAGIC_LUMP_2, new ItemStack(Material.BONE_MEAL), SlimefunItems.MAGIC_LUMP_2, new ItemStack(Material.NETHER_WART), new ItemStack(Material.BLAZE_POWDER), new ItemStack(Material.NETHER_WART)}, new CustomItem(SlimefunItems.INFERNAL_BONEMEAL, 8)) diff --git a/src/main/resources/languages/messages_en.yml b/src/main/resources/languages/messages_en.yml index 397bb69bb..f2b46c3ac 100644 --- a/src/main/resources/languages/messages_en.yml +++ b/src/main/resources/languages/messages_en.yml @@ -129,6 +129,10 @@ messages: soulbound-rune: fail: '&cYou can only bind one item to your soul at a time.' success: '&aYou have successfully bound this item to your soul! You will keep it when you die.' + + enchantment-rune: + fail: '&cYou cannot enchant this item.' + success: '&aYou have successfully applied a random applicable enchantment to this item.' research: start: '&7The Ancient Spirits whisper mysterious words into your ear!' diff --git a/src/main/resources/languages/researches_en.yml b/src/main/resources/languages/researches_en.yml index 744c95ffd..f6af8ff9e 100644 --- a/src/main/resources/languages/researches_en.yml +++ b/src/main/resources/languages/researches_en.yml @@ -233,4 +233,6 @@ slimefun: tree_growth_accelerator: Faster Trees industrial_miner: Industrial Mining advanced_industrial_miner: Better Mining - magic_pills: De-Zombification \ No newline at end of file + magic_pills: De-Zombification + enchantment_rune: Ancient Enchanting + magical_glass: Magical See-Through \ No newline at end of file From e1fc23c265ced97b7d40dbf66e20a225c17513be Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Wed, 24 Jun 2020 21:27:27 +0300 Subject: [PATCH 02/20] Fixed an import dis-organisation. --- .../slimefun4/implementation/setup/SlimefunItemSetup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index 35d650778..c532d3583 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -3,7 +3,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.setup; import java.util.ArrayList; import java.util.List; -import io.github.thebusybiscuit.slimefun4.implementation.items.magical.EnchantmentRune; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; @@ -117,6 +116,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.gps.GPSTransmitte import io.github.thebusybiscuit.slimefun4.implementation.items.gps.PersonalActivationPlate; import io.github.thebusybiscuit.slimefun4.implementation.items.gps.Teleporter; import io.github.thebusybiscuit.slimefun4.implementation.items.gps.TeleporterPylon; +import io.github.thebusybiscuit.slimefun4.implementation.items.magical.EnchantmentRune; import io.github.thebusybiscuit.slimefun4.implementation.items.magical.InfernalBonemeal; import io.github.thebusybiscuit.slimefun4.implementation.items.magical.InfusedMagnet; import io.github.thebusybiscuit.slimefun4.implementation.items.magical.KnowledgeFlask; From eb2bbae0c986691229fd0fcb069af8f3737d4151 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Fri, 26 Jun 2020 13:31:45 +0300 Subject: [PATCH 03/20] Did the requested changes. --- .../items/magical/EnchantmentRune.java | 52 ++++--------------- 1 file changed, 11 insertions(+), 41 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java index 83a46b521..c166b4303 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java @@ -1,7 +1,10 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.magical; import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; import java.util.Optional; +import java.util.Set; import java.util.concurrent.ThreadLocalRandom; import org.bukkit.Location; @@ -14,7 +17,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.inventory.ItemStack; -import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; @@ -38,34 +40,18 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class EnchantmentRune extends SimpleSlimefunItem { private static final double RANGE = 1.5; - - private static final Enchantment[] helmEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.OXYGEN, Enchantment.WATER_WORKER, Enchantment.THORNS, Enchantment.PROTECTION_PROJECTILE, Enchantment.PROTECTION_FIRE, Enchantment.PROTECTION_ENVIRONMENTAL, Enchantment.PROTECTION_EXPLOSIONS}; - private static final Enchantment[] chestLeggingsEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.THORNS, Enchantment.PROTECTION_PROJECTILE, Enchantment.PROTECTION_FIRE, Enchantment.PROTECTION_ENVIRONMENTAL, Enchantment.PROTECTION_EXPLOSIONS}; - private static final Enchantment[] bootsEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.FROST_WALKER, Enchantment.PROTECTION_FALL, Enchantment.DEPTH_STRIDER, Enchantment.THORNS, Enchantment.PROTECTION_PROJECTILE, Enchantment.PROTECTION_FIRE, Enchantment.PROTECTION_ENVIRONMENTAL, Enchantment.PROTECTION_EXPLOSIONS}; - - private static final Enchantment[] swordEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.FIRE_ASPECT, Enchantment.LOOT_BONUS_MOBS, Enchantment.KNOCKBACK, Enchantment.SWEEPING_EDGE, Enchantment.DAMAGE_ALL, Enchantment.DAMAGE_ARTHROPODS, Enchantment.DAMAGE_UNDEAD}; - private static final Enchantment[] tridentEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.IMPALING, Enchantment.CHANNELING, Enchantment.LOYALTY, Enchantment.RIPTIDE}; - private static Enchantment[] crossbowEnch; - private static final Enchantment[] bowEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.ARROW_DAMAGE, Enchantment.ARROW_FIRE, Enchantment.ARROW_INFINITE, Enchantment.ARROW_KNOCKBACK}; - - private static final Enchantment[] axeEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.DIG_SPEED, Enchantment.LOOT_BONUS_BLOCKS, Enchantment.SILK_TOUCH, Enchantment.DAMAGE_ALL, Enchantment.DAMAGE_UNDEAD, Enchantment.DAMAGE_ARTHROPODS}; - private static final Enchantment[] toolEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.DIG_SPEED, Enchantment.LOOT_BONUS_BLOCKS, Enchantment.SILK_TOUCH}; - private static final Enchantment[] shearEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.DIG_SPEED}; - private static final Enchantment[] fishRodEnch = {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.LURE, Enchantment.LUCK}; - private static final Enchantment[] otherItemsEnch = {Enchantment.MENDING, Enchantment.DURABILITY}; + private final HashMap applicableEnchs = new HashMap<>(); public EnchantmentRune(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); - } - @Override - public void preRegister() { - if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14)) { - crossbowEnch = new Enchantment[] {Enchantment.MENDING, Enchantment.DURABILITY, Enchantment.MULTISHOT, Enchantment.QUICK_CHARGE, Enchantment.PIERCING}; - } else { - crossbowEnch = null; + for (Material mat : Material.values()) { + Set enchSet = new HashSet<>(); + for (Enchantment ench : Enchantment.values()) { + if (ench.canEnchantItem(new ItemStack(mat))) enchSet.add(ench); + } + applicableEnchs.put(mat, enchSet.toArray(new Enchantment[0])); } - super.preRegister(); } @Override @@ -137,23 +123,7 @@ public class EnchantmentRune extends SimpleSlimefunItem { } private Enchantment[] findEnchArr(Material type) { - Enchantment[] enchArr = null; - - if (type.name().endsWith("_HELMET")) enchArr = helmEnch; - if (type.name().endsWith("_CHESTPLATE") || type.name().endsWith("_LEGGINGS")) enchArr = chestLeggingsEnch; - if (type.name().endsWith("_BOOTS")) enchArr = bootsEnch; - if (type.name().endsWith("_SWORD")) enchArr = swordEnch; - if (type.name().endsWith("_AXE")) enchArr = axeEnch; - if (type.name().endsWith("_PICKAXE") || type.name().endsWith("_SHOVEL") || type.name().endsWith("_HOE")) enchArr = toolEnch; - - if (type == Material.TRIDENT) enchArr = tridentEnch; - if (type == Material.BOW) enchArr = bowEnch; - if (type == Material.SHEARS) enchArr = shearEnch; - if (type == Material.FISHING_ROD) enchArr = fishRodEnch; - if (crossbowEnch != null && type.name().equals("CROSSBOW")) enchArr = crossbowEnch; - - if (type == Material.SHIELD || type == Material.ELYTRA || type == Material.CARROT_ON_A_STICK || type == Material.FLINT_AND_STEEL) enchArr = otherItemsEnch; - + Enchantment[] enchArr = applicableEnchs.get(type); if (enchArr == null) enchArr = new Enchantment[0]; return enchArr; } From cd4a36c519702f21e7ae0affc853695557cbb821 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Fri, 26 Jun 2020 23:18:27 +0300 Subject: [PATCH 04/20] Added Bee Protection to Hazmat Suit. --- .../listeners/HazmatSuitListener.java | 59 +++++++++++++++++++ .../Slimefun/SlimefunPlugin.java | 2 + 2 files changed, 61 insertions(+) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/HazmatSuitListener.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/HazmatSuitListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/HazmatSuitListener.java new file mode 100644 index 000000000..3af80370a --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/HazmatSuitListener.java @@ -0,0 +1,59 @@ +package io.github.thebusybiscuit.slimefun4.implementation.listeners; + +import org.bukkit.entity.Bee; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.inventory.ItemStack; + +import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; + +/** + * The listener for Hazmat Suit's {@link Bee} sting protection. + * Only applied if the whole set is worn. + * + * @author Linox + * + * @see Bee + * + */ +public class HazmatSuitListener implements Listener { + + public HazmatSuitListener(SlimefunPlugin plugin) { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @EventHandler + public void onDamage(EntityDamageByEntityEvent e) { + if (!SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_15)) return; + + if (e.getDamager() instanceof Bee) { + if (e.getEntity() instanceof Player) { + Player p = (Player) e.getEntity(); + + int hazmatCount = 0; + for (ItemStack armor : p.getInventory().getArmorContents()) { + SlimefunItem sfItem = SlimefunItem.getByItem(armor); + if (sfItem == null) return; + + String id = sfItem.getID(); + if (id.equals("SCUBA_HELMET")) hazmatCount++; + if (id.equals("HAZMAT_CHESTPLATE")) hazmatCount++; + if (id.equals("HAZMAT_LEGGINGS")) hazmatCount++; + if (id.equals("RUBBER_BOOTS")) hazmatCount++; + } + + if (hazmatCount == 4) { + e.setDamage(0D); + for (ItemStack armor : p.getInventory().getArmorContents()) { + ItemUtils.damageItem(armor, 1, false); + } + } + } + } + } +} diff --git a/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java b/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java index 635821e44..0c5480ad8 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java @@ -10,6 +10,7 @@ import java.util.Set; import java.util.logging.Level; import java.util.stream.Collectors; +import io.github.thebusybiscuit.slimefun4.implementation.listeners.HazmatSuitListener; import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.command.Command; @@ -237,6 +238,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { new WitherListener(this); new IronGolemListener(this); new PlayerInteractEntityListener(this); + new HazmatSuitListener(this); new MobDropListener(this, (BasicCircuitBoard) SlimefunItems.BASIC_CIRCUIT_BOARD.getItem()); From 29fe88176873b8eb7cf791d0caab0ab53644a6a4 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Fri, 26 Jun 2020 23:31:15 +0300 Subject: [PATCH 05/20] Added a new lore to Hazmat Suit for 1.15+ --- .../slimefun4/implementation/SlimefunItems.java | 7 +++++++ .../Slimefun/api/SlimefunItemStack.java | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java index 6d9cf0fb1..0f177404d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java @@ -296,6 +296,13 @@ public final class SlimefunItems { REINFORCED_ALLOY_LEGGINGS.addUnsafeEnchantments(reinforced); REINFORCED_ALLOY_BOOTS.addUnsafeEnchantments(reinforced); + if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_15)) { + SCUBA_HELMET.addLore("", "&7Equip the full set for:", "&7+Bee Protection"); + HAZMAT_CHESTPLATE.addLore("", "&7Equip the full set for:", "&7+Bee Protection"); + HAZMAT_LEGGINGS.addLore("", "&7Equip the full set for:", "&7+Bee Protection"); + RUBBER_BOOTS.addLore("", "&7Equip the full set for:", "&7+Bee Protection"); + } + Map gilded = new HashMap<>(); gilded.put(Enchantment.DURABILITY, 6); gilded.put(Enchantment.PROTECTION_ENVIRONMENTAL, 8); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java b/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java index 6d7ed0e50..aab0762b3 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java @@ -2,6 +2,7 @@ package me.mrCookieSlime.Slimefun.api; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; import java.util.Base64; import java.util.List; import java.util.Locale; @@ -245,4 +246,20 @@ public class SlimefunItemStack extends CustomItem { } } + /** + * Adds additional lores for the {@link ItemStack}. + * + * @param newLore + * New lores to be added to the {@link ItemStack} + */ + public void addLore(String... newLore) { + ItemMeta meta = getItemMeta(); + if (meta == null) return; + List oldLore = meta.getLore(); + if (oldLore == null) return; + + oldLore.addAll(Arrays.asList(newLore)); + meta.setLore(oldLore); + setItemMeta(meta); + } } From ffd57ec760cd2fb977a67bb8d84b9190dd2485ac Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Sat, 27 Jun 2020 01:51:38 +0300 Subject: [PATCH 06/20] Did the requested Changes --- .../implementation/SlimefunItems.java | 30 ++++++++++++++++--- ...zmatSuitListener.java => BeeListener.java} | 30 ++++++------------- .../implementation/tasks/ArmorTask.java | 5 +++- .../Slimefun/SlimefunPlugin.java | 6 ++-- .../Slimefun/api/SlimefunItemStack.java | 17 ----------- 5 files changed, 43 insertions(+), 45 deletions(-) rename src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/{HazmatSuitListener.java => BeeListener.java} (53%) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java index 0f177404d..d78ef5c93 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java @@ -1,6 +1,8 @@ package io.github.thebusybiscuit.slimefun4.implementation; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.bukkit.Color; @@ -297,10 +299,30 @@ public final class SlimefunItems { REINFORCED_ALLOY_BOOTS.addUnsafeEnchantments(reinforced); if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_15)) { - SCUBA_HELMET.addLore("", "&7Equip the full set for:", "&7+Bee Protection"); - HAZMAT_CHESTPLATE.addLore("", "&7Equip the full set for:", "&7+Bee Protection"); - HAZMAT_LEGGINGS.addLore("", "&7Equip the full set for:", "&7+Bee Protection"); - RUBBER_BOOTS.addLore("", "&7Equip the full set for:", "&7+Bee Protection"); + + ItemMeta scubaHelmetMeta = SCUBA_HELMET.getItemMeta(); + List scubaHelmetMetaLore = scubaHelmetMeta.getLore(); + scubaHelmetMetaLore.addAll(Arrays.asList("", "&7Equip the full set for:", "&7+Bee Protection")); + scubaHelmetMeta.setLore(scubaHelmetMetaLore); + SCUBA_HELMET.setItemMeta(scubaHelmetMeta); + + ItemMeta hazmatChestplateItemMeta = HAZMAT_CHESTPLATE.getItemMeta(); + List hazmatChestplateItemMetaLore = hazmatChestplateItemMeta.getLore(); + hazmatChestplateItemMetaLore.addAll(Arrays.asList("", "&7Equip the full set for:", "&7+Bee Protection")); + hazmatChestplateItemMeta.setLore(hazmatChestplateItemMetaLore); + HAZMAT_CHESTPLATE.setItemMeta(hazmatChestplateItemMeta); + + ItemMeta hazmatLeggingsItemMeta = HAZMAT_LEGGINGS.getItemMeta(); + List hazmatLeggingsItemMetaLore = hazmatLeggingsItemMeta.getLore(); + hazmatLeggingsItemMetaLore.addAll(Arrays.asList("", "&7Equip the full set for:", "&7+Bee Protection")); + hazmatLeggingsItemMeta.setLore(hazmatLeggingsItemMetaLore); + HAZMAT_LEGGINGS.setItemMeta(hazmatLeggingsItemMeta); + + ItemMeta rubberBootsItemMeta = RUBBER_BOOTS.getItemMeta(); + List rubberBootsItemMetaLore = rubberBootsItemMeta.getLore(); + rubberBootsItemMetaLore.addAll(Arrays.asList("", "&7Equip the full set for:", "&7+Bee Protection")); + rubberBootsItemMeta.setLore(rubberBootsItemMetaLore); + RUBBER_BOOTS.setItemMeta(rubberBootsItemMeta); } Map gilded = new HashMap<>(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/HazmatSuitListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java similarity index 53% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/HazmatSuitListener.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java index 3af80370a..b7738e1b7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/HazmatSuitListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java @@ -8,8 +8,8 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; -import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; +import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.Slimefun.SlimefunPlugin; /** @@ -18,36 +18,24 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin; * * @author Linox * - * @see Bee - * */ -public class HazmatSuitListener implements Listener { +public class BeeListener implements Listener { - public HazmatSuitListener(SlimefunPlugin plugin) { + public BeeListener(SlimefunPlugin plugin) { plugin.getServer().getPluginManager().registerEvents(this, plugin); } @EventHandler public void onDamage(EntityDamageByEntityEvent e) { - if (!SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_15)) return; - if (e.getDamager() instanceof Bee) { if (e.getEntity() instanceof Player) { Player p = (Player) e.getEntity(); - int hazmatCount = 0; - for (ItemStack armor : p.getInventory().getArmorContents()) { - SlimefunItem sfItem = SlimefunItem.getByItem(armor); - if (sfItem == null) return; - - String id = sfItem.getID(); - if (id.equals("SCUBA_HELMET")) hazmatCount++; - if (id.equals("HAZMAT_CHESTPLATE")) hazmatCount++; - if (id.equals("HAZMAT_LEGGINGS")) hazmatCount++; - if (id.equals("RUBBER_BOOTS")) hazmatCount++; - } - - if (hazmatCount == 4) { + // Check for a Hazmat Suit + if (!SlimefunUtils.isItemSimilar(SlimefunItems.SCUBA_HELMET, p.getInventory().getHelmet(), true) && + !SlimefunUtils.isItemSimilar(SlimefunItems.HAZMAT_CHESTPLATE, p.getInventory().getChestplate(), true) && + !SlimefunUtils.isItemSimilar(SlimefunItems.HAZMAT_LEGGINGS, p.getInventory().getLeggings(), true) && + !SlimefunUtils.isItemSimilar(SlimefunItems.RUBBER_BOOTS, p.getInventory().getBoots(), true)) { e.setDamage(0D); for (ItemStack armor : p.getInventory().getArmorContents()) { ItemUtils.damageItem(armor, 1, false); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java index e3809b012..db7a6ed1e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java @@ -107,7 +107,10 @@ public class ArmorTask implements Runnable { private void checkForRadiation(Player p) { // Check for a Hazmat Suit - if (!SlimefunUtils.isItemSimilar(SlimefunItems.SCUBA_HELMET, p.getInventory().getHelmet(), true) || !SlimefunUtils.isItemSimilar(SlimefunItems.HAZMAT_CHESTPLATE, p.getInventory().getChestplate(), true) || !SlimefunUtils.isItemSimilar(SlimefunItems.HAZMAT_LEGGINGS, p.getInventory().getLeggings(), true) || !SlimefunUtils.isItemSimilar(SlimefunItems.RUBBER_BOOTS, p.getInventory().getBoots(), true)) { + if (!SlimefunUtils.isItemSimilar(SlimefunItems.SCUBA_HELMET, p.getInventory().getHelmet(), true) || + !SlimefunUtils.isItemSimilar(SlimefunItems.HAZMAT_CHESTPLATE, p.getInventory().getChestplate(), true) || + !SlimefunUtils.isItemSimilar(SlimefunItems.HAZMAT_LEGGINGS, p.getInventory().getLeggings(), true) || + !SlimefunUtils.isItemSimilar(SlimefunItems.RUBBER_BOOTS, p.getInventory().getBoots(), true)) { for (ItemStack item : p.getInventory()) { if (isRadioactive(p, item)) { break; diff --git a/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java b/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java index 0c5480ad8..1f125642c 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java @@ -10,7 +10,6 @@ import java.util.Set; import java.util.logging.Level; import java.util.stream.Collectors; -import io.github.thebusybiscuit.slimefun4.implementation.listeners.HazmatSuitListener; import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.command.Command; @@ -54,6 +53,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SeismicAx import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.VampireBlade; import io.github.thebusybiscuit.slimefun4.implementation.listeners.AncientAltarListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.BackpackListener; +import io.github.thebusybiscuit.slimefun4.implementation.listeners.BeeListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.BlockListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.BlockPhysicsListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.CargoNodeListener; @@ -238,7 +238,9 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { new WitherListener(this); new IronGolemListener(this); new PlayerInteractEntityListener(this); - new HazmatSuitListener(this); + if (minecraftVersion.isAtLeast(MinecraftVersion.MINECRAFT_1_15)) { + new BeeListener(this); + } new MobDropListener(this, (BasicCircuitBoard) SlimefunItems.BASIC_CIRCUIT_BOARD.getItem()); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java b/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java index aab0762b3..0b3f1975b 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java @@ -245,21 +245,4 @@ public class SlimefunItemStack extends CustomItem { throw new IllegalArgumentException("The provided texture for Item \"" + id + "\" does not seem to be a valid texture String!"); } } - - /** - * Adds additional lores for the {@link ItemStack}. - * - * @param newLore - * New lores to be added to the {@link ItemStack} - */ - public void addLore(String... newLore) { - ItemMeta meta = getItemMeta(); - if (meta == null) return; - List oldLore = meta.getLore(); - if (oldLore == null) return; - - oldLore.addAll(Arrays.asList(newLore)); - meta.setLore(oldLore); - setItemMeta(meta); - } } From 73973a00b722b897449a91a9bdf2fd246eb94c53 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Sat, 27 Jun 2020 12:26:15 +0300 Subject: [PATCH 07/20] Did the requested changes and some fixes. --- .../slimefun4/api/player/PlayerProfile.java | 1 + .../implementation/SlimefunItems.java | 17 ++++++-- .../implementation/listeners/BeeListener.java | 43 ++++++++++++++----- .../setup/SlimefunItemSetup.java | 24 +++++------ .../implementation/tasks/ArmorTask.java | 28 +++++++++--- .../Slimefun/api/SlimefunItemStack.java | 1 - 6 files changed, 79 insertions(+), 35 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java index 30e85d15e..18f8b7cd0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java @@ -47,6 +47,7 @@ import me.mrCookieSlime.Slimefun.api.Slimefun; * @see Research * @see Waypoint * @see PlayerBackpack + * @see HashedArmorpiece * */ public final class PlayerProfile { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java index d78ef5c93..04dcef725 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -302,25 +303,33 @@ public final class SlimefunItems { ItemMeta scubaHelmetMeta = SCUBA_HELMET.getItemMeta(); List scubaHelmetMetaLore = scubaHelmetMeta.getLore(); - scubaHelmetMetaLore.addAll(Arrays.asList("", "&7Equip the full set for:", "&7+Bee Protection")); + scubaHelmetMetaLore.addAll(Arrays.asList("", + ChatColor.translateAlternateColorCodes('&', "&7Equip the full set for:"), + ChatColor.translateAlternateColorCodes('&', "&7+Bee Protection"))); scubaHelmetMeta.setLore(scubaHelmetMetaLore); SCUBA_HELMET.setItemMeta(scubaHelmetMeta); ItemMeta hazmatChestplateItemMeta = HAZMAT_CHESTPLATE.getItemMeta(); List hazmatChestplateItemMetaLore = hazmatChestplateItemMeta.getLore(); - hazmatChestplateItemMetaLore.addAll(Arrays.asList("", "&7Equip the full set for:", "&7+Bee Protection")); + hazmatChestplateItemMetaLore.addAll(Arrays.asList("", + ChatColor.translateAlternateColorCodes('&', "&7Equip the full set for:"), + ChatColor.translateAlternateColorCodes('&', "&7+Bee Protection"))); hazmatChestplateItemMeta.setLore(hazmatChestplateItemMetaLore); HAZMAT_CHESTPLATE.setItemMeta(hazmatChestplateItemMeta); ItemMeta hazmatLeggingsItemMeta = HAZMAT_LEGGINGS.getItemMeta(); List hazmatLeggingsItemMetaLore = hazmatLeggingsItemMeta.getLore(); - hazmatLeggingsItemMetaLore.addAll(Arrays.asList("", "&7Equip the full set for:", "&7+Bee Protection")); + hazmatLeggingsItemMetaLore.addAll(Arrays.asList("", + ChatColor.translateAlternateColorCodes('&', "&7Equip the full set for:"), + ChatColor.translateAlternateColorCodes('&', "&7+Bee Protection"))); hazmatLeggingsItemMeta.setLore(hazmatLeggingsItemMetaLore); HAZMAT_LEGGINGS.setItemMeta(hazmatLeggingsItemMeta); ItemMeta rubberBootsItemMeta = RUBBER_BOOTS.getItemMeta(); List rubberBootsItemMetaLore = rubberBootsItemMeta.getLore(); - rubberBootsItemMetaLore.addAll(Arrays.asList("", "&7Equip the full set for:", "&7+Bee Protection")); + rubberBootsItemMetaLore.addAll(Arrays.asList("", + ChatColor.translateAlternateColorCodes('&', "&7Equip the full set for:"), + ChatColor.translateAlternateColorCodes('&', "&7+Bee Protection"))); rubberBootsItemMeta.setLore(rubberBootsItemMetaLore); RUBBER_BOOTS.setItemMeta(rubberBootsItemMeta); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java index b7738e1b7..a23335ece 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.listeners; +import java.util.Optional; + import org.bukkit.entity.Bee; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -8,8 +10,9 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; -import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; -import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import io.github.thebusybiscuit.slimefun4.api.items.HashedArmorpiece; +import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; +import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; import me.mrCookieSlime.Slimefun.SlimefunPlugin; /** @@ -30,18 +33,36 @@ public class BeeListener implements Listener { if (e.getDamager() instanceof Bee) { if (e.getEntity() instanceof Player) { Player p = (Player) e.getEntity(); + PlayerProfile.get(p, profile -> { - // Check for a Hazmat Suit - if (!SlimefunUtils.isItemSimilar(SlimefunItems.SCUBA_HELMET, p.getInventory().getHelmet(), true) && - !SlimefunUtils.isItemSimilar(SlimefunItems.HAZMAT_CHESTPLATE, p.getInventory().getChestplate(), true) && - !SlimefunUtils.isItemSimilar(SlimefunItems.HAZMAT_LEGGINGS, p.getInventory().getLeggings(), true) && - !SlimefunUtils.isItemSimilar(SlimefunItems.RUBBER_BOOTS, p.getInventory().getBoots(), true)) { - e.setDamage(0D); - for (ItemStack armor : p.getInventory().getArmorContents()) { - ItemUtils.damageItem(armor, 1, false); + HashedArmorpiece[] armors = profile.getArmor(); + if (hasFullHazmat(armors)) { + for (ItemStack armor : p.getInventory().getArmorContents()) { + ItemUtils.damageItem(armor, 1, false); + } + e.setDamage(0D); } - } + }); } } } + + private boolean hasFullHazmat(HashedArmorpiece[] armors) { + int hazmatCount = 0; + + // Check for a Hazmat Suit + for (HashedArmorpiece armor : armors) { + Optional armorPiece = armor.getItem(); + if (!armorPiece.isPresent()) return false; + + if (armorPiece.get().getID().equals("SCUBA_HELMET") || + armorPiece.get().getID().equals("HAZMAT_CHESTPLATE") || + armorPiece.get().getID().equals("HAZMAT_LEGGINGS") || + armorPiece.get().getID().equals("RUBBER_BOOTS")) { + hazmatCount++; + } + } + + return hazmatCount == 4; + } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index 33335b37d..1395f213f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -348,12 +348,12 @@ public final class SlimefunItemSetup { new ItemStack[] {SlimefunItems.SALT, new ItemStack(Material.ROTTEN_FLESH), null, null, null, null, null, null, null}) .register(plugin); - new SlimefunItem(categories.magicalArmor, SlimefunItems.SLIME_HELMET, RecipeType.ARMOR_FORGE, - new ItemStack[] {new ItemStack(Material.SLIME_BALL), new ItemStack(Material.IRON_INGOT), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.IRON_INGOT), null, new ItemStack(Material.IRON_INGOT), null, null, null}) + new SlimefunArmorPiece(categories.magicalArmor, SlimefunItems.SLIME_HELMET, RecipeType.ARMOR_FORGE, + new ItemStack[] {new ItemStack(Material.SLIME_BALL), new ItemStack(Material.IRON_INGOT), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.IRON_INGOT), null, new ItemStack(Material.IRON_INGOT), null, null, null}, null) .register(plugin); - new SlimefunItem(categories.magicalArmor, SlimefunItems.SLIME_CHESTPLATE, RecipeType.ARMOR_FORGE, - new ItemStack[] {new ItemStack(Material.SLIME_BALL), null, new ItemStack(Material.SLIME_BALL), new ItemStack(Material.IRON_INGOT), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.IRON_INGOT), new ItemStack(Material.IRON_INGOT), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.IRON_INGOT)}) + new SlimefunArmorPiece(categories.magicalArmor, SlimefunItems.SLIME_CHESTPLATE, RecipeType.ARMOR_FORGE, + new ItemStack[] {new ItemStack(Material.SLIME_BALL), null, new ItemStack(Material.SLIME_BALL), new ItemStack(Material.IRON_INGOT), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.IRON_INGOT), new ItemStack(Material.IRON_INGOT), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.IRON_INGOT)}, null) .register(plugin); new SlimefunArmorPiece(categories.magicalArmor, SlimefunItems.SLIME_LEGGINGS, RecipeType.ARMOR_FORGE, @@ -913,12 +913,12 @@ public final class SlimefunItemSetup { new PotionEffect[] {new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 300, 1)}) .register(plugin); - new SlimefunItem(categories.armor, SlimefunItems.HAZMAT_LEGGINGS, RecipeType.ARMOR_FORGE, - new ItemStack[] {new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL)}) + new SlimefunArmorPiece(categories.armor, SlimefunItems.HAZMAT_LEGGINGS, RecipeType.ARMOR_FORGE, + new ItemStack[] {new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL)}, null) .register(plugin); - new SlimefunItem(categories.armor, SlimefunItems.RUBBER_BOOTS, RecipeType.ARMOR_FORGE, - new ItemStack[] {null, null, null, new ItemStack(Material.BLACK_WOOL), null, new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), null, new ItemStack(Material.BLACK_WOOL)}) + new SlimefunArmorPiece(categories.armor, SlimefunItems.RUBBER_BOOTS, RecipeType.ARMOR_FORGE, + new ItemStack[] {null, null, null, new ItemStack(Material.BLACK_WOOL), null, new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), null, new ItemStack(Material.BLACK_WOOL)}, null) .register(plugin); new SlimefunItem(categories.misc, SlimefunItems.CRUSHED_ORE, RecipeType.ORE_CRUSHER, @@ -1002,12 +1002,12 @@ public final class SlimefunItemSetup { new TableSaw(categories.basicMachines, SlimefunItems.TABLE_SAW).register(plugin); } - new SlimefunItem(categories.magicalArmor, SlimefunItems.SLIME_HELMET_STEEL, RecipeType.ARMOR_FORGE, - new ItemStack[] {new ItemStack(Material.SLIME_BALL), SlimefunItems.STEEL_PLATE, new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), null, new ItemStack(Material.SLIME_BALL), null, null, null}) + new SlimefunArmorPiece(categories.magicalArmor, SlimefunItems.SLIME_HELMET_STEEL, RecipeType.ARMOR_FORGE, + new ItemStack[] {new ItemStack(Material.SLIME_BALL), SlimefunItems.STEEL_PLATE, new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), null, new ItemStack(Material.SLIME_BALL), null, null, null}, null) .register(plugin); - new SlimefunItem(categories.magicalArmor, SlimefunItems.SLIME_CHESTPLATE_STEEL, RecipeType.ARMOR_FORGE, - new ItemStack[] {new ItemStack(Material.SLIME_BALL), null, new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), SlimefunItems.STEEL_PLATE, new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL)}) + new SlimefunArmorPiece(categories.magicalArmor, SlimefunItems.SLIME_CHESTPLATE_STEEL, RecipeType.ARMOR_FORGE, + new ItemStack[] {new ItemStack(Material.SLIME_BALL), null, new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), SlimefunItems.STEEL_PLATE, new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL)}, null) .register(plugin); new SlimefunArmorPiece(categories.magicalArmor, SlimefunItems.SLIME_LEGGINGS_STEEL, RecipeType.ARMOR_FORGE, diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java index f10eaf0d2..8203ee9d3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java @@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.tasks; import java.util.Collections; import java.util.HashSet; +import java.util.Optional; import java.util.Set; import org.bukkit.Bukkit; @@ -63,7 +64,7 @@ public class ArmorTask implements Runnable { checkForSolarHelmet(p); } - checkForRadiation(p); + checkForRadiation(profile); }); } } @@ -119,13 +120,26 @@ public class ArmorTask implements Runnable { return (world.getTime() < 12300 || world.getTime() > 23850) && p.getEyeLocation().getBlock().getLightFromSky() == 15; } - private void checkForRadiation(Player p) { + private void checkForRadiation(PlayerProfile profile) { + HashedArmorpiece[] armor = profile.getArmor(); + Player p = profile.getPlayer(); + // Check for a Hazmat Suit - if (!SlimefunUtils.isItemSimilar(SlimefunItems.SCUBA_HELMET, p.getInventory().getHelmet(), true) || - !SlimefunUtils.isItemSimilar(SlimefunItems.HAZMAT_CHESTPLATE, p.getInventory().getChestplate(), true) || - !SlimefunUtils.isItemSimilar(SlimefunItems.HAZMAT_LEGGINGS, p.getInventory().getLeggings(), true) || - !SlimefunUtils.isItemSimilar(SlimefunItems.RUBBER_BOOTS, p.getInventory().getBoots(), true)) { - if (!SlimefunUtils.isItemSimilar(p.getInventory().getHelmet(), SlimefunItems.SCUBA_HELMET, true) || !SlimefunUtils.isItemSimilar(p.getInventory().getChestplate(), SlimefunItems.HAZMAT_CHESTPLATE, true) || !SlimefunUtils.isItemSimilar(p.getInventory().getLeggings(), SlimefunItems.HAZMAT_LEGGINGS, true) || !SlimefunUtils.isItemSimilar(p.getInventory().getBoots(), SlimefunItems.RUBBER_BOOTS, true)) { + boolean hasHazmat = false; + for (HashedArmorpiece armorPiece : armor) { + + Optional sfArmor = armorPiece.getItem(); + if (!sfArmor.isPresent()) continue; + + if (sfArmor.get().getID().equals("SCUBA_HELMET") || + sfArmor.get().getID().equals("HAZMAT_CHESTPLATE") || + sfArmor.get().getID().equals("HAZMAT_LEGGINGS") || + sfArmor.get().getID().equals("RUBBER_BOOTS")) { + hasHazmat = true; + } + } + + if (!hasHazmat) { for (ItemStack item : p.getInventory()) { if (isRadioactive(p, item)) { break; diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java b/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java index 0b3f1975b..bca914aeb 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java @@ -2,7 +2,6 @@ package me.mrCookieSlime.Slimefun.api; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Arrays; import java.util.Base64; import java.util.List; import java.util.Locale; From b5ef8ff019f0af88e96cb03330dfb9d4ba12ac0d Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Sat, 27 Jun 2020 15:58:36 +0300 Subject: [PATCH 08/20] Did the requested changes + improvements. --- .../core/attributes/CustomProtection.java | 48 +++++++++++++++ .../items/armor/HazmatArmorPiece.java | 30 ++++++++++ .../items/armor/SlimefunArmorPiece.java | 15 +++++ .../implementation/listeners/BeeListener.java | 60 ++++++++++++------- .../setup/SlimefunItemSetup.java | 17 +++--- .../implementation/tasks/ArmorTask.java | 58 +++++++++++------- 6 files changed, 178 insertions(+), 50 deletions(-) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/CustomProtection.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/CustomProtection.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/CustomProtection.java new file mode 100644 index 000000000..c142ca7fc --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/CustomProtection.java @@ -0,0 +1,48 @@ +package io.github.thebusybiscuit.slimefun4.core.attributes; + +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityDamageEvent; + +import io.github.thebusybiscuit.slimefun4.implementation.items.armor.HazmatArmorPiece; +import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; + +/** + * Implement this interface for any {@link SlimefunArmorPiece} to prevent + * the {@link Player} wearing that {@link SlimefunArmorPiece} + * + * Important: This will not cancel any {@link EntityDamageEvent}. + * It will simply prevent Slimefun from ever applying {@link ProtectionType} + * to this {@link SlimefunArmorPiece}'s wearer. + * + * @author Linox + * + * @see SlimefunArmorPiece + * @see HazmatArmorPiece + * @see ItemAttribute + * + */ +public interface CustomProtection extends ItemAttribute { + + /** + * This returns the {@link ProtectionType}s this {@link ItemAttribute} + * prevents the assigned {@link SlimefunArmorPiece} to be damaged by. + * + * @return The {@link ProtectionType}s + */ + ProtectionType[] getProtectionTypes(); + + /** + * This returns the {@link ProtectionType}s this {@link ItemAttribute} + * prevents the assigned {@link SlimefunArmorPiece} to be damaged by. + * + * @return The {@link ProtectionType}s + */ + boolean requireFullSet(); + + enum ProtectionType { + + RADIATION, + + BEES; + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java new file mode 100644 index 000000000..0216d1036 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java @@ -0,0 +1,30 @@ +package io.github.thebusybiscuit.slimefun4.implementation.items.armor; + +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; + +import io.github.thebusybiscuit.slimefun4.core.attributes.CustomProtection; +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; + +public class HazmatArmorPiece extends SlimefunArmorPiece implements CustomProtection { + + private final ProtectionType[] types; + + public HazmatArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects, String setID) { + super(category, item, recipeType, recipe, effects, setID); + + types = new ProtectionType[] {ProtectionType.BEES, ProtectionType.RADIATION}; + } + + @Override + public ProtectionType[] getProtectionTypes() { + return types; + } + + @Override + public boolean requireFullSet() { + return true; + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java index 925934c64..40c8540ad 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java @@ -11,6 +11,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class SlimefunArmorPiece extends SlimefunItem { + private String setID = null; private final PotionEffect[] effects; public SlimefunArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects) { @@ -19,6 +20,12 @@ public class SlimefunArmorPiece extends SlimefunItem { this.effects = effects == null ? new PotionEffect[0] : effects; } + public SlimefunArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects, String setID) { + this(category, item, recipeType, recipe, effects); + + this.setID = setID; + } + /** * An Array of {@link PotionEffect PotionEffects} which get applied to a {@link Player} wearing * this {@link SlimefunArmorPiece}. @@ -29,4 +36,12 @@ public class SlimefunArmorPiece extends SlimefunItem { return effects; } + /** + * This returns the armor set ID of this {@link SlimefunArmorPiece}. + * + * @return The set ID, null if no set ID is found. + */ + public String getSetID() { + return setID; + } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java index a23335ece..57b54b787 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java @@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.listeners; import java.util.Optional; +import io.github.thebusybiscuit.slimefun4.core.attributes.CustomProtection; import org.bukkit.entity.Bee; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -12,6 +13,7 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; import io.github.thebusybiscuit.slimefun4.api.items.HashedArmorpiece; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; +import io.github.thebusybiscuit.slimefun4.implementation.items.armor.HazmatArmorPiece; import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; import me.mrCookieSlime.Slimefun.SlimefunPlugin; @@ -30,39 +32,55 @@ public class BeeListener implements Listener { @EventHandler public void onDamage(EntityDamageByEntityEvent e) { - if (e.getDamager() instanceof Bee) { - if (e.getEntity() instanceof Player) { - Player p = (Player) e.getEntity(); - PlayerProfile.get(p, profile -> { + if (e.getDamager() instanceof Bee && e.getEntity() instanceof Player) { - HashedArmorpiece[] armors = profile.getArmor(); - if (hasFullHazmat(armors)) { - for (ItemStack armor : p.getInventory().getArmorContents()) { - ItemUtils.damageItem(armor, 1, false); - } - e.setDamage(0D); - } - }); + Player p = (Player) e.getEntity(); + Optional optional = PlayerProfile.find(p); + if (!optional.isPresent()) { + PlayerProfile.request(p); + return; + } + PlayerProfile profile = optional.get(); + + HashedArmorpiece[] armors = profile.getArmor(); + if (shouldProtect(armors)) { + for (ItemStack armor : p.getInventory().getArmorContents()) { + ItemUtils.damageItem(armor, 1, false); + } + e.setDamage(0D); } } } - private boolean hasFullHazmat(HashedArmorpiece[] armors) { - int hazmatCount = 0; + private boolean shouldProtect(HashedArmorpiece[] armors) { + int armorCount = 0; + boolean first = true; - // Check for a Hazmat Suit + String setID = null; for (HashedArmorpiece armor : armors) { Optional armorPiece = armor.getItem(); if (!armorPiece.isPresent()) return false; - if (armorPiece.get().getID().equals("SCUBA_HELMET") || - armorPiece.get().getID().equals("HAZMAT_CHESTPLATE") || - armorPiece.get().getID().equals("HAZMAT_LEGGINGS") || - armorPiece.get().getID().equals("RUBBER_BOOTS")) { - hazmatCount++; + if (armorPiece.get() instanceof CustomProtection) { + CustomProtection protectedArmor = (CustomProtection) armorPiece.get(); + + if (first) { + if (protectedArmor.requireFullSet()) setID = armorPiece.get().getSetID(); + first = false; + } + + for (CustomProtection.ProtectionType protectionType : protectedArmor.getProtectionTypes()) { + if (protectionType == CustomProtection.ProtectionType.BEES) { + if (setID == null) { + return true; + } + armorCount++; + } + } + } } - return hazmatCount == 4; + return armorCount == 4; } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index 1395f213f..f0b0d6e71 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -3,6 +3,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.setup; import java.util.ArrayList; import java.util.List; +import io.github.thebusybiscuit.slimefun4.implementation.items.armor.HazmatArmorPiece; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; @@ -903,22 +904,22 @@ public final class SlimefunItemSetup { SlimefunItems.GILDED_IRON_HELMET, SlimefunItems.GILDED_IRON_CHESTPLATE, SlimefunItems.GILDED_IRON_LEGGINGS, SlimefunItems.GILDED_IRON_BOOTS }, "GILDED_IRON", false, plugin); - new SlimefunArmorPiece(categories.armor, SlimefunItems.SCUBA_HELMET, RecipeType.ARMOR_FORGE, + new HazmatArmorPiece(categories.armor, SlimefunItems.SCUBA_HELMET, RecipeType.ARMOR_FORGE, new ItemStack[] {new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.GLASS_PANE), new ItemStack(Material.BLACK_WOOL), null, null, null}, - new PotionEffect[] {new PotionEffect(PotionEffectType.WATER_BREATHING, 300, 1)}) + new PotionEffect[] {new PotionEffect(PotionEffectType.WATER_BREATHING, 300, 1)}, "HAZMAT_SUIT") .register(plugin); - new SlimefunArmorPiece(categories.armor, SlimefunItems.HAZMAT_CHESTPLATE, RecipeType.ARMOR_FORGE, + new HazmatArmorPiece(categories.armor, SlimefunItems.HAZMAT_CHESTPLATE, RecipeType.ARMOR_FORGE, new ItemStack[] {new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL)}, - new PotionEffect[] {new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 300, 1)}) + new PotionEffect[] {new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 300, 1)}, "HAZMAT_SUIT") .register(plugin); - new SlimefunArmorPiece(categories.armor, SlimefunItems.HAZMAT_LEGGINGS, RecipeType.ARMOR_FORGE, - new ItemStack[] {new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL)}, null) + new HazmatArmorPiece(categories.armor, SlimefunItems.HAZMAT_LEGGINGS, RecipeType.ARMOR_FORGE, + new ItemStack[] {new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL)}, null, "HAZMAT_SUIT") .register(plugin); - new SlimefunArmorPiece(categories.armor, SlimefunItems.RUBBER_BOOTS, RecipeType.ARMOR_FORGE, - new ItemStack[] {null, null, null, new ItemStack(Material.BLACK_WOOL), null, new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), null, new ItemStack(Material.BLACK_WOOL)}, null) + new HazmatArmorPiece(categories.armor, SlimefunItems.RUBBER_BOOTS, RecipeType.ARMOR_FORGE, + new ItemStack[] {null, null, null, new ItemStack(Material.BLACK_WOOL), null, new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), null, new ItemStack(Material.BLACK_WOOL)}, null, "HAZMAT_SUIT") .register(plugin); new SlimefunItem(categories.misc, SlimefunItems.CRUSHED_ORE, RecipeType.ORE_CRUSHER, diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java index 8203ee9d3..69dd15444 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java @@ -15,6 +15,7 @@ import org.bukkit.potion.PotionEffectType; import io.github.thebusybiscuit.slimefun4.api.items.HashedArmorpiece; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; +import io.github.thebusybiscuit.slimefun4.core.attributes.CustomProtection; import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; @@ -64,7 +65,7 @@ public class ArmorTask implements Runnable { checkForSolarHelmet(p); } - checkForRadiation(profile); + checkForRadiation(p, profile); }); } } @@ -120,35 +121,19 @@ public class ArmorTask implements Runnable { return (world.getTime() < 12300 || world.getTime() > 23850) && p.getEyeLocation().getBlock().getLightFromSky() == 15; } - private void checkForRadiation(PlayerProfile profile) { + private void checkForRadiation(Player p, PlayerProfile profile) { HashedArmorpiece[] armor = profile.getArmor(); - Player p = profile.getPlayer(); - // Check for a Hazmat Suit - boolean hasHazmat = false; - for (HashedArmorpiece armorPiece : armor) { - - Optional sfArmor = armorPiece.getItem(); - if (!sfArmor.isPresent()) continue; - - if (sfArmor.get().getID().equals("SCUBA_HELMET") || - sfArmor.get().getID().equals("HAZMAT_CHESTPLATE") || - sfArmor.get().getID().equals("HAZMAT_LEGGINGS") || - sfArmor.get().getID().equals("RUBBER_BOOTS")) { - hasHazmat = true; - } - } - - if (!hasHazmat) { + if (!shouldProtect(armor)) { for (ItemStack item : p.getInventory()) { - if (isRadioactive(p, item)) { + if (checkAndApplyRadioactive(p, item)) { break; } } } } - private boolean isRadioactive(Player p, ItemStack item) { + private boolean checkAndApplyRadioactive(Player p, ItemStack item) { for (SlimefunItem radioactiveItem : SlimefunPlugin.getRegistry().getRadioactiveItems()) { if (radioactiveItem.isItem(item) && Slimefun.isEnabled(p, radioactiveItem, true)) { // If the item is enabled in the world, then make radioactivity do its job @@ -166,4 +151,35 @@ public class ArmorTask implements Runnable { return false; } + private boolean shouldProtect(HashedArmorpiece[] armors) { + int armorCount = 0; + boolean first = true; + + String setID = null; + for (HashedArmorpiece armor : armors) { + Optional armorPiece = armor.getItem(); + if (!armorPiece.isPresent()) return false; + + if (armorPiece.get() instanceof CustomProtection) { + CustomProtection protectedArmor = (CustomProtection) armorPiece.get(); + + if (first) { + if (protectedArmor.requireFullSet()) setID = armorPiece.get().getSetID(); + first = false; + } + + for (CustomProtection.ProtectionType protectionType : protectedArmor.getProtectionTypes()) { + if (protectionType == CustomProtection.ProtectionType.RADIATION) { + if (setID == null) { + return true; + } + armorCount++; + } + } + + } + } + + return armorCount == 4; + } } From a456034005cc99cd89aacd91c5842609dce50ba8 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Sat, 27 Jun 2020 16:07:22 +0300 Subject: [PATCH 09/20] Fixed merge conflicts. --- .../slimefun4/implementation/SlimefunPlugin.java | 4 ++++ .../slimefun4/implementation/listeners/BeeListener.java | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java index 3da4f58f4..e0a6e764f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java @@ -52,6 +52,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SeismicAx import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.VampireBlade; import io.github.thebusybiscuit.slimefun4.implementation.listeners.AncientAltarListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.BackpackListener; +import io.github.thebusybiscuit.slimefun4.implementation.listeners.BeeListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.BlockListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.BlockPhysicsListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.CargoNodeListener; @@ -236,6 +237,9 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { new WitherListener(this); new IronGolemListener(this); new PlayerInteractEntityListener(this); + if (minecraftVersion.isAtLeast(MinecraftVersion.MINECRAFT_1_15)) { + new BeeListener(this); + } new MobDropListener(this, (BasicCircuitBoard) SlimefunItems.BASIC_CIRCUIT_BOARD.getItem()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java index 57b54b787..c5897f96e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java @@ -2,7 +2,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.listeners; import java.util.Optional; -import io.github.thebusybiscuit.slimefun4.core.attributes.CustomProtection; import org.bukkit.entity.Bee; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -13,9 +12,9 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; import io.github.thebusybiscuit.slimefun4.api.items.HashedArmorpiece; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; -import io.github.thebusybiscuit.slimefun4.implementation.items.armor.HazmatArmorPiece; +import io.github.thebusybiscuit.slimefun4.core.attributes.CustomProtection; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; -import me.mrCookieSlime.Slimefun.SlimefunPlugin; /** * The listener for Hazmat Suit's {@link Bee} sting protection. From 64a1b247b4518577a32006ce1692218a5399af52 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Sat, 27 Jun 2020 17:30:28 +0300 Subject: [PATCH 10/20] Did the requested changes + fixes. --- .../slimefun4/api/items/HashedArmorpiece.java | 2 +- .../slimefun4/api/player/PlayerProfile.java | 37 ++++++++++++++++ .../core/attributes/CustomProtection.java | 9 +--- .../core/attributes/ProtectionType.java | 8 ++++ .../items/armor/HazmatArmorPiece.java | 3 +- .../items/armor/SlimefunArmorPiece.java | 16 ++++--- .../implementation/listeners/BeeListener.java | 40 ++--------------- .../implementation/tasks/ArmorTask.java | 43 ++----------------- 8 files changed, 65 insertions(+), 93 deletions(-) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/ProtectionType.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/HashedArmorpiece.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/HashedArmorpiece.java index afb0cd4be..a848cadca 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/HashedArmorpiece.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/HashedArmorpiece.java @@ -78,7 +78,7 @@ public final class HashedArmorpiece { */ public boolean hasDiverged(ItemStack stack) { if (stack == null || stack.getType() == Material.AIR) { - return hash == 0; + return hash != 0; } else { ItemStack copy = stack.clone(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java index ddf5fcde5..793438edb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java @@ -19,6 +19,7 @@ import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.NamespacedKey; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -31,9 +32,12 @@ import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; import io.github.thebusybiscuit.cscorelib2.config.Config; import io.github.thebusybiscuit.slimefun4.api.gps.Waypoint; import io.github.thebusybiscuit.slimefun4.api.items.HashedArmorpiece; +import io.github.thebusybiscuit.slimefun4.core.attributes.CustomProtection; +import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType; import io.github.thebusybiscuit.slimefun4.core.guide.GuideHistory; import io.github.thebusybiscuit.slimefun4.core.researching.Research; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; +import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; import me.mrCookieSlime.Slimefun.api.Slimefun; @@ -449,6 +453,39 @@ public final class PlayerProfile { } } + public boolean isProtected(ProtectionType type) { + int armorCount = 0; + boolean first = true; + + NamespacedKey setId = null; + for (HashedArmorpiece armor : armor) { + Optional armorPiece = armor.getItem(); + if (!armorPiece.isPresent()) return false; + + if (armorPiece.get() instanceof CustomProtection) { + CustomProtection protectedArmor = (CustomProtection) armorPiece.get(); + + if (first) { + if (protectedArmor.isFullSetRequired()) setId = armorPiece.get().getSetId(); + first = false; + } + + for (ProtectionType protectionType : protectedArmor.getProtectionTypes()) { + if (protectionType == type) { + if (setId == null) { + return true; + } else if (setId.equals(armorPiece.get().getSetId())) { + armorCount++; + } + } + } + + } + } + + return armorCount == 4; + } + @Override public int hashCode() { return uuid.hashCode(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/CustomProtection.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/CustomProtection.java index c142ca7fc..f6b7af88e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/CustomProtection.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/CustomProtection.java @@ -37,12 +37,5 @@ public interface CustomProtection extends ItemAttribute { * * @return The {@link ProtectionType}s */ - boolean requireFullSet(); - - enum ProtectionType { - - RADIATION, - - BEES; - } + boolean isFullSetRequired(); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/ProtectionType.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/ProtectionType.java new file mode 100644 index 000000000..c4b74703f --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/ProtectionType.java @@ -0,0 +1,8 @@ +package io.github.thebusybiscuit.slimefun4.core.attributes; + +public enum ProtectionType { + + RADIATION, + BEES; + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java index 0216d1036..16db6724a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java @@ -4,6 +4,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import io.github.thebusybiscuit.slimefun4.core.attributes.CustomProtection; +import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; @@ -24,7 +25,7 @@ public class HazmatArmorPiece extends SlimefunArmorPiece implements CustomProtec } @Override - public boolean requireFullSet() { + public boolean isFullSetRequired() { return true; } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java index 40c8540ad..9d48d6a40 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java @@ -1,9 +1,11 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.armor; +import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; @@ -11,7 +13,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class SlimefunArmorPiece extends SlimefunItem { - private String setID = null; + private NamespacedKey id = null; private final PotionEffect[] effects; public SlimefunArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects) { @@ -20,10 +22,10 @@ public class SlimefunArmorPiece extends SlimefunItem { this.effects = effects == null ? new PotionEffect[0] : effects; } - public SlimefunArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects, String setID) { + public SlimefunArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects, String setId) { this(category, item, recipeType, recipe, effects); - this.setID = setID; + this.id = new NamespacedKey(SlimefunPlugin.instance, setId); } /** @@ -37,11 +39,11 @@ public class SlimefunArmorPiece extends SlimefunItem { } /** - * This returns the armor set ID of this {@link SlimefunArmorPiece}. + * This returns the armor set {@link NamespacedKey} of this {@link SlimefunArmorPiece}. * - * @return The set ID, null if no set ID is found. + * @return The set {@link NamespacedKey}, null if none is found. */ - public String getSetID() { - return setID; + public NamespacedKey getSetId() { + return id; } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java index c5897f96e..c45531d5a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java @@ -10,11 +10,9 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; -import io.github.thebusybiscuit.slimefun4.api.items.HashedArmorpiece; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; -import io.github.thebusybiscuit.slimefun4.core.attributes.CustomProtection; +import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; /** * The listener for Hazmat Suit's {@link Bee} sting protection. @@ -39,10 +37,9 @@ public class BeeListener implements Listener { PlayerProfile.request(p); return; } - PlayerProfile profile = optional.get(); - HashedArmorpiece[] armors = profile.getArmor(); - if (shouldProtect(armors)) { + PlayerProfile profile = optional.get(); + if (profile.isProtected(ProtectionType.BEES)) { for (ItemStack armor : p.getInventory().getArmorContents()) { ItemUtils.damageItem(armor, 1, false); } @@ -51,35 +48,4 @@ public class BeeListener implements Listener { } } - private boolean shouldProtect(HashedArmorpiece[] armors) { - int armorCount = 0; - boolean first = true; - - String setID = null; - for (HashedArmorpiece armor : armors) { - Optional armorPiece = armor.getItem(); - if (!armorPiece.isPresent()) return false; - - if (armorPiece.get() instanceof CustomProtection) { - CustomProtection protectedArmor = (CustomProtection) armorPiece.get(); - - if (first) { - if (protectedArmor.requireFullSet()) setID = armorPiece.get().getSetID(); - first = false; - } - - for (CustomProtection.ProtectionType protectionType : protectedArmor.getProtectionTypes()) { - if (protectionType == CustomProtection.ProtectionType.BEES) { - if (setID == null) { - return true; - } - armorCount++; - } - } - - } - } - - return armorCount == 4; - } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java index 1ac187eca..17351980f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java @@ -2,7 +2,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.tasks; import java.util.Collections; import java.util.HashSet; -import java.util.Optional; import java.util.Set; import org.bukkit.Bukkit; @@ -15,7 +14,7 @@ import org.bukkit.potion.PotionEffectType; import io.github.thebusybiscuit.slimefun4.api.items.HashedArmorpiece; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; -import io.github.thebusybiscuit.slimefun4.core.attributes.CustomProtection; +import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType; import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; @@ -122,18 +121,16 @@ public class ArmorTask implements Runnable { } private void checkForRadiation(Player p, PlayerProfile profile) { - HashedArmorpiece[] armor = profile.getArmor(); - - if (!shouldProtect(armor)) { + if (!profile.isProtected(ProtectionType.RADIATION)) { for (ItemStack item : p.getInventory()) { - if (checkAndApplyRadioactive(p, item)) { + if (checkAndApplyRadiation(p, item)) { break; } } } } - private boolean checkAndApplyRadioactive(Player p, ItemStack item) { + private boolean checkAndApplyRadiation(Player p, ItemStack item) { for (SlimefunItem radioactiveItem : SlimefunPlugin.getRegistry().getRadioactiveItems()) { if (radioactiveItem.isItem(item) && Slimefun.isEnabled(p, radioactiveItem, true)) { // If the item is enabled in the world, then make radioactivity do its job @@ -150,36 +147,4 @@ public class ArmorTask implements Runnable { return false; } - - private boolean shouldProtect(HashedArmorpiece[] armors) { - int armorCount = 0; - boolean first = true; - - String setID = null; - for (HashedArmorpiece armor : armors) { - Optional armorPiece = armor.getItem(); - if (!armorPiece.isPresent()) return false; - - if (armorPiece.get() instanceof CustomProtection) { - CustomProtection protectedArmor = (CustomProtection) armorPiece.get(); - - if (first) { - if (protectedArmor.requireFullSet()) setID = armorPiece.get().getSetID(); - first = false; - } - - for (CustomProtection.ProtectionType protectionType : protectedArmor.getProtectionTypes()) { - if (protectionType == CustomProtection.ProtectionType.RADIATION) { - if (setID == null) { - return true; - } - armorCount++; - } - } - - } - } - - return armorCount == 4; - } } From 07d837299ff3feae12eeeb6f37b4891f661a50f6 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Sun, 28 Jun 2020 01:07:37 +0300 Subject: [PATCH 11/20] Did the requested changes. --- .../core/attributes/ProtectionType.java | 9 +++++++++ .../items/armor/HazmatArmorPiece.java | 16 ++++++++++++++-- .../items/armor/SlimefunArmorPiece.java | 5 ++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/ProtectionType.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/ProtectionType.java index c4b74703f..5fbc54eeb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/ProtectionType.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/ProtectionType.java @@ -1,5 +1,14 @@ package io.github.thebusybiscuit.slimefun4.core.attributes; +/** + * Represents the {@link ProtectionType} that a {@link CustomProtection} + * prevents the damage from. + * + * @author Linox + * + * @see CustomProtection + * + */ public enum ProtectionType { RADIATION, diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java index 16db6724a..dc49b0c83 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java @@ -1,20 +1,32 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.armor; +import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import io.github.thebusybiscuit.slimefun4.core.attributes.CustomProtection; import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +/** + * Represents 1 {@link SlimefunArmorPiece} of the Hazmat armor set. + * One of the very few utilisations of {@link CustomProtection}. + * + * @author Linox + * + * @see SlimefunArmorPiece + * @see CustomProtection + * + */ public class HazmatArmorPiece extends SlimefunArmorPiece implements CustomProtection { private final ProtectionType[] types; - public HazmatArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects, String setID) { - super(category, item, recipeType, recipe, effects, setID); + public HazmatArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects) { + super(category, item, recipeType, recipe, effects, new NamespacedKey(SlimefunPlugin.instance, "hazmat_suit")); types = new ProtectionType[] {ProtectionType.BEES, ProtectionType.RADIATION}; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java index 9d48d6a40..306238eb1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java @@ -22,10 +22,9 @@ public class SlimefunArmorPiece extends SlimefunItem { this.effects = effects == null ? new PotionEffect[0] : effects; } - public SlimefunArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects, String setId) { + public SlimefunArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects, NamespacedKey setId) { this(category, item, recipeType, recipe, effects); - - this.id = new NamespacedKey(SlimefunPlugin.instance, setId); + this.id = setId; } /** From a935951c229dc1c04646dcd9e72b03b30b81fc6d Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Sun, 28 Jun 2020 01:14:37 +0300 Subject: [PATCH 12/20] Oops forgot to change these. --- .../implementation/setup/SlimefunItemSetup.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index 40c05de1d..dc6940c50 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -3,7 +3,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.setup; import java.util.ArrayList; import java.util.List; -import io.github.thebusybiscuit.slimefun4.implementation.items.armor.HazmatArmorPiece; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; @@ -31,6 +30,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.androids.FisherAn import io.github.thebusybiscuit.slimefun4.implementation.items.androids.MinerAndroid; import io.github.thebusybiscuit.slimefun4.implementation.items.androids.ProgrammableAndroid; import io.github.thebusybiscuit.slimefun4.implementation.items.androids.WoodcutterAndroid; +import io.github.thebusybiscuit.slimefun4.implementation.items.armor.HazmatArmorPiece; import io.github.thebusybiscuit.slimefun4.implementation.items.armor.Parachute; import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler; @@ -906,20 +906,20 @@ public final class SlimefunItemSetup { new HazmatArmorPiece(categories.armor, SlimefunItems.SCUBA_HELMET, RecipeType.ARMOR_FORGE, new ItemStack[] {new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.GLASS_PANE), new ItemStack(Material.BLACK_WOOL), null, null, null}, - new PotionEffect[] {new PotionEffect(PotionEffectType.WATER_BREATHING, 300, 1)}, "HAZMAT_SUIT") + new PotionEffect[] {new PotionEffect(PotionEffectType.WATER_BREATHING, 300, 1)}) .register(plugin); new HazmatArmorPiece(categories.armor, SlimefunItems.HAZMAT_CHESTPLATE, RecipeType.ARMOR_FORGE, new ItemStack[] {new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL)}, - new PotionEffect[] {new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 300, 1)}, "HAZMAT_SUIT") + new PotionEffect[] {new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 300, 1)}) .register(plugin); new HazmatArmorPiece(categories.armor, SlimefunItems.HAZMAT_LEGGINGS, RecipeType.ARMOR_FORGE, - new ItemStack[] {new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL)}, null, "HAZMAT_SUIT") + new ItemStack[] {new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL)}, null) .register(plugin); new HazmatArmorPiece(categories.armor, SlimefunItems.RUBBER_BOOTS, RecipeType.ARMOR_FORGE, - new ItemStack[] {null, null, null, new ItemStack(Material.BLACK_WOOL), null, new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), null, new ItemStack(Material.BLACK_WOOL)}, null, "HAZMAT_SUIT") + new ItemStack[] {null, null, null, new ItemStack(Material.BLACK_WOOL), null, new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), null, new ItemStack(Material.BLACK_WOOL)}, null) .register(plugin); new SlimefunItem(categories.misc, SlimefunItems.CRUSHED_ORE, RecipeType.ORE_CRUSHER, From 3e271ac78631bd975f95c18a34da7ab3e1de9c75 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Sun, 28 Jun 2020 05:29:51 +0300 Subject: [PATCH 13/20] Did more requested changes. --- .../slimefun4/api/player/PlayerProfile.java | 8 ++--- .../core/attributes/CustomProtection.java | 30 ++++++++++++------- .../implementation/SlimefunItems.java | 19 ++++++------ .../items/armor/HazmatArmorPiece.java | 9 +++++- .../items/armor/SlimefunArmorPiece.java | 17 ----------- 5 files changed, 39 insertions(+), 44 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java index 793438edb..74a2bf75a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java @@ -455,7 +455,6 @@ public final class PlayerProfile { public boolean isProtected(ProtectionType type) { int armorCount = 0; - boolean first = true; NamespacedKey setId = null; for (HashedArmorpiece armor : armor) { @@ -465,16 +464,15 @@ public final class PlayerProfile { if (armorPiece.get() instanceof CustomProtection) { CustomProtection protectedArmor = (CustomProtection) armorPiece.get(); - if (first) { - if (protectedArmor.isFullSetRequired()) setId = armorPiece.get().getSetId(); - first = false; + if (setId == null && protectedArmor.isFullSetRequired()) { + setId = protectedArmor.getSetId(); } for (ProtectionType protectionType : protectedArmor.getProtectionTypes()) { if (protectionType == type) { if (setId == null) { return true; - } else if (setId.equals(armorPiece.get().getSetId())) { + } else if (setId.equals(protectedArmor.getSetId())) { armorCount++; } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/CustomProtection.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/CustomProtection.java index f6b7af88e..8a24a4cc2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/CustomProtection.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/CustomProtection.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.core.attributes; +import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; @@ -7,12 +8,12 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.armor.HazmatArmor import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; /** - * Implement this interface for any {@link SlimefunArmorPiece} to prevent - * the {@link Player} wearing that {@link SlimefunArmorPiece} + * Implement this interface to a {@link SlimefunArmorPiece} to protect + * the {@link Player} who wears that {@link SlimefunArmorPiece} from + * {@link ProtectionType} damage. * - * Important: This will not cancel any {@link EntityDamageEvent}. - * It will simply prevent Slimefun from ever applying {@link ProtectionType} - * to this {@link SlimefunArmorPiece}'s wearer. + * Important: You need to specify which {@link ProtectionType} damages + * to protect the {@link Player} from. * * @author Linox * @@ -24,18 +25,25 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArm public interface CustomProtection extends ItemAttribute { /** - * This returns the {@link ProtectionType}s this {@link ItemAttribute} - * prevents the assigned {@link SlimefunArmorPiece} to be damaged by. + * This returns which {@link ProtectionType} damages this {@link ItemAttribute} + * will protect the {@link Player} from. * - * @return The {@link ProtectionType}s + * @return The {@link ProtectionType}s. */ ProtectionType[] getProtectionTypes(); /** - * This returns the {@link ProtectionType}s this {@link ItemAttribute} - * prevents the assigned {@link SlimefunArmorPiece} to be damaged by. + * This returns whether the full set is required for {@link Player}'s protection on + * assigned {@link ProtectionType} damages. * - * @return The {@link ProtectionType}s + * @return Whether or not he full set is required. */ boolean isFullSetRequired(); + + /** + * This returns the armor set {@link NamespacedKey} of this {@link SlimefunArmorPiece}. + * + * @return The set {@link NamespacedKey}, null if none is found. + */ + NamespacedKey getSetId(); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java index 6d124d54c..1be536b0e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java @@ -5,7 +5,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -14,6 +13,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.core.attributes.MachineTier; import io.github.thebusybiscuit.slimefun4.core.attributes.MachineType; @@ -299,36 +299,35 @@ public final class SlimefunItems { REINFORCED_ALLOY_BOOTS.addUnsafeEnchantments(reinforced); if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_15)) { - ItemMeta scubaHelmetMeta = SCUBA_HELMET.getItemMeta(); List scubaHelmetMetaLore = scubaHelmetMeta.getLore(); scubaHelmetMetaLore.addAll(Arrays.asList("", - ChatColor.translateAlternateColorCodes('&', "&7Equip the full set for:"), - ChatColor.translateAlternateColorCodes('&', "&7+Bee Protection"))); + ChatColors.color( "&7Equip the full set for:"), + ChatColors.color( "&7+Bee Protection"))); scubaHelmetMeta.setLore(scubaHelmetMetaLore); SCUBA_HELMET.setItemMeta(scubaHelmetMeta); ItemMeta hazmatChestplateItemMeta = HAZMAT_CHESTPLATE.getItemMeta(); List hazmatChestplateItemMetaLore = hazmatChestplateItemMeta.getLore(); hazmatChestplateItemMetaLore.addAll(Arrays.asList("", - ChatColor.translateAlternateColorCodes('&', "&7Equip the full set for:"), - ChatColor.translateAlternateColorCodes('&', "&7+Bee Protection"))); + ChatColors.color( "&7Equip the full set for:"), + ChatColors.color( "&7+Bee Protection"))); hazmatChestplateItemMeta.setLore(hazmatChestplateItemMetaLore); HAZMAT_CHESTPLATE.setItemMeta(hazmatChestplateItemMeta); ItemMeta hazmatLeggingsItemMeta = HAZMAT_LEGGINGS.getItemMeta(); List hazmatLeggingsItemMetaLore = hazmatLeggingsItemMeta.getLore(); hazmatLeggingsItemMetaLore.addAll(Arrays.asList("", - ChatColor.translateAlternateColorCodes('&', "&7Equip the full set for:"), - ChatColor.translateAlternateColorCodes('&', "&7+Bee Protection"))); + ChatColors.color( "&7Equip the full set for:"), + ChatColors.color( "&7+Bee Protection"))); hazmatLeggingsItemMeta.setLore(hazmatLeggingsItemMetaLore); HAZMAT_LEGGINGS.setItemMeta(hazmatLeggingsItemMeta); ItemMeta rubberBootsItemMeta = RUBBER_BOOTS.getItemMeta(); List rubberBootsItemMetaLore = rubberBootsItemMeta.getLore(); rubberBootsItemMetaLore.addAll(Arrays.asList("", - ChatColor.translateAlternateColorCodes('&', "&7Equip the full set for:"), - ChatColor.translateAlternateColorCodes('&', "&7+Bee Protection"))); + ChatColors.color( "&7Equip the full set for:"), + ChatColors.color( "&7+Bee Protection"))); rubberBootsItemMeta.setLore(rubberBootsItemMetaLore); RUBBER_BOOTS.setItemMeta(rubberBootsItemMeta); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java index dc49b0c83..3e55f1515 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java @@ -23,12 +23,14 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; */ public class HazmatArmorPiece extends SlimefunArmorPiece implements CustomProtection { + private final NamespacedKey setId; private final ProtectionType[] types; public HazmatArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects) { - super(category, item, recipeType, recipe, effects, new NamespacedKey(SlimefunPlugin.instance, "hazmat_suit")); + super(category, item, recipeType, recipe, effects); types = new ProtectionType[] {ProtectionType.BEES, ProtectionType.RADIATION}; + setId = new NamespacedKey(SlimefunPlugin.instance, "hazmat_suit"); } @Override @@ -40,4 +42,9 @@ public class HazmatArmorPiece extends SlimefunArmorPiece implements CustomProtec public boolean isFullSetRequired() { return true; } + + @Override + public NamespacedKey getSetId() { + return setId; + } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java index 306238eb1..47473bab7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java @@ -1,11 +1,9 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.armor; -import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; -import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; @@ -13,7 +11,6 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class SlimefunArmorPiece extends SlimefunItem { - private NamespacedKey id = null; private final PotionEffect[] effects; public SlimefunArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects) { @@ -22,11 +19,6 @@ public class SlimefunArmorPiece extends SlimefunItem { this.effects = effects == null ? new PotionEffect[0] : effects; } - public SlimefunArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects, NamespacedKey setId) { - this(category, item, recipeType, recipe, effects); - this.id = setId; - } - /** * An Array of {@link PotionEffect PotionEffects} which get applied to a {@link Player} wearing * this {@link SlimefunArmorPiece}. @@ -36,13 +28,4 @@ public class SlimefunArmorPiece extends SlimefunItem { public PotionEffect[] getPotionEffects() { return effects; } - - /** - * This returns the armor set {@link NamespacedKey} of this {@link SlimefunArmorPiece}. - * - * @return The set {@link NamespacedKey}, null if none is found. - */ - public NamespacedKey getSetId() { - return id; - } } From e55e2690e78067bf2615ec5926f5878c6ed1317b Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Sun, 28 Jun 2020 22:06:35 +0300 Subject: [PATCH 14/20] Did the requested changes. --- .../items/magical/EnchantmentRune.java | 41 +++++++++++-------- .../implementation/setup/ResearchSetup.java | 3 +- .../resources/languages/researches_en.yml | 3 +- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java index c166b4303..f650cad7b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java @@ -1,14 +1,18 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.magical; +import java.util.Arrays; import java.util.Collection; -import java.util.HashMap; +import java.util.EnumMap; import java.util.HashSet; +import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.concurrent.ThreadLocalRandom; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Particle; import org.bukkit.Sound; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Entity; @@ -40,7 +44,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class EnchantmentRune extends SimpleSlimefunItem { private static final double RANGE = 1.5; - private final HashMap applicableEnchs = new HashMap<>(); + private final Map applicableEnchantments = new EnumMap<>(Material.class); public EnchantmentRune(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); @@ -50,7 +54,7 @@ public class EnchantmentRune extends SimpleSlimefunItem { for (Enchantment ench : Enchantment.values()) { if (ench.canEnchantItem(new ItemStack(mat))) enchSet.add(ench); } - applicableEnchs.put(mat, enchSet.toArray(new Enchantment[0])); + applicableEnchantments.put(mat, enchSet.toArray(new Enchantment[0])); } } @@ -85,15 +89,22 @@ public class EnchantmentRune extends SimpleSlimefunItem { Item entity = (Item) optional.get(); ItemStack target = entity.getItemStack(); - Enchantment[] enchArr = findEnchArr(target.getType()); - if (enchArr.length == 0) return; - int enchIndex = ThreadLocalRandom.current().nextInt(enchArr.length); - Enchantment ench = enchArr[enchIndex]; + List enchantmentSet = Arrays.asList(applicableEnchantments.getOrDefault(target.getType(), new Enchantment[0])); + if (enchantmentSet.size() == 0) return; + //Removing the enchantments that the item already has from enchantmentSet + for (Enchantment enchantment : enchantmentSet) { + for (Enchantment itemEnchantment : target.getEnchantments().keySet()) { + if (enchantment == itemEnchantment) enchantmentSet.remove(enchantment); + } + } + + Enchantment enchantment = enchantmentSet.get(ThreadLocalRandom.current().nextInt(enchantmentSet.size())); int level = 1; - if (ench.getMaxLevel() != 1) level = ThreadLocalRandom.current().nextInt(ench.getMaxLevel() + 1); - - target.addEnchantment(ench, level); + if (enchantment.getMaxLevel() != 1) { + level = ThreadLocalRandom.current().nextInt(enchantment.getMaxLevel() + 1); + } + target.addEnchantment(enchantment, level); if (target.getAmount() == 1) { e.setCancelled(true); @@ -105,8 +116,8 @@ public class EnchantmentRune extends SimpleSlimefunItem { // Being sure entities are still valid and not picked up or whatsoever. if (item.isValid() && entity.isValid() && target.getAmount() == 1) { - l.getWorld().createExplosion(l, 0); - l.getWorld().playSound(l, Sound.ENTITY_GENERIC_EXPLODE, 0.3F, 1); + l.getWorld().spawnParticle(Particle.CRIT_MAGIC, l, 1); + l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_VILLAGER_CURE, 1F, 1F); entity.remove(); item.remove(); @@ -122,12 +133,6 @@ public class EnchantmentRune extends SimpleSlimefunItem { } } - private Enchantment[] findEnchArr(Material type) { - Enchantment[] enchArr = applicableEnchs.get(type); - if (enchArr == null) enchArr = new Enchantment[0]; - return enchArr; - } - private boolean findCompatibleItem(Entity n) { if (n instanceof Item) { Item item = (Item) n; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java index 5590c31db..9b480651e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java @@ -267,8 +267,7 @@ public final class ResearchSetup { register("advanced_industrial_miner", 98, "Better Mining", 36, SlimefunItems.ADVANCED_INDUSTRIAL_MINER); register("magical_zombie_pills", 257, "De-Zombification", 22, SlimefunItems.MAGICAL_ZOMBIE_PILLS); register("auto_brewer", 258, "Industrial Brewery", 30, SlimefunItems.AUTO_BREWER); - register("enchantment_rune", 259, "Ancient Enchanting", 24, SlimefunItems.ENCHANTMENT_RUNE); - register("magical_glass", 260, "Magical See-Through", 5, SlimefunItems.MAGICAL_GLASS); + register("enchantment_rune", 259, "Ancient Enchanting", 24, SlimefunItems.MAGICAL_GLASS, SlimefunItems.ENCHANTMENT_RUNE); } private static void register(String key, int id, String name, int defaultCost, ItemStack... items) { diff --git a/src/main/resources/languages/researches_en.yml b/src/main/resources/languages/researches_en.yml index 4c7109749..3b9073a5e 100644 --- a/src/main/resources/languages/researches_en.yml +++ b/src/main/resources/languages/researches_en.yml @@ -235,5 +235,4 @@ slimefun: advanced_industrial_miner: Better Mining magical_zombie_pills: De-Zombification auto_brewer: Industrial Brewery - enchantment_rune: Ancient Enchanting - magical_glass: Magical See-Through \ No newline at end of file + enchantment_rune: Ancient Enchanting \ No newline at end of file From 27ba744fe5ce0d42aa5f42ab4cdebdcb7e8a587e Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Sun, 28 Jun 2020 22:09:04 +0300 Subject: [PATCH 15/20] Fixed a little bug. --- .../slimefun4/implementation/items/magical/EnchantmentRune.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java index f650cad7b..aed5ce6b6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java @@ -102,7 +102,7 @@ public class EnchantmentRune extends SimpleSlimefunItem { Enchantment enchantment = enchantmentSet.get(ThreadLocalRandom.current().nextInt(enchantmentSet.size())); int level = 1; if (enchantment.getMaxLevel() != 1) { - level = ThreadLocalRandom.current().nextInt(enchantment.getMaxLevel() + 1); + level = ThreadLocalRandom.current().nextInt(enchantment.getMaxLevel()) + 1; } target.addEnchantment(enchantment, level); From 5c7accbbe8a4d3377ae9bada48de126e189d2202 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Sun, 28 Jun 2020 23:46:09 +0300 Subject: [PATCH 16/20] Did the requested changes + a fix. --- .../items/magical/EnchantmentRune.java | 31 ++++++++----------- .../items/magical/SoulboundRune.java | 2 +- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java index aed5ce6b6..65f22d345 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java @@ -1,13 +1,11 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.magical; -import java.util.Arrays; +import java.util.ArrayList; import java.util.Collection; import java.util.EnumMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.Set; import java.util.concurrent.ThreadLocalRandom; import org.bukkit.Location; @@ -21,7 +19,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.inventory.ItemStack; -import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; @@ -44,17 +41,18 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class EnchantmentRune extends SimpleSlimefunItem { private static final double RANGE = 1.5; - private final Map applicableEnchantments = new EnumMap<>(Material.class); + private final Map> applicableEnchantments = new EnumMap<>(Material.class); public EnchantmentRune(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); for (Material mat : Material.values()) { - Set enchSet = new HashSet<>(); - for (Enchantment ench : Enchantment.values()) { - if (ench.canEnchantItem(new ItemStack(mat))) enchSet.add(ench); + List enchantments = new ArrayList<>(); + for (Enchantment enchantment : Enchantment.values()) { + if (enchantment == Enchantment.BINDING_CURSE || enchantment == Enchantment.VANISHING_CURSE) continue; + if (enchantment.canEnchantItem(new ItemStack(mat))) enchantments.add(enchantment); } - applicableEnchantments.put(mat, enchSet.toArray(new Enchantment[0])); + applicableEnchantments.put(mat, enchantments); } } @@ -63,7 +61,7 @@ public class EnchantmentRune extends SimpleSlimefunItem { return (e, p, item) -> { if (isItem(item.getItemStack())) { - if (!Slimefun.hasUnlocked(p, SlimefunItems.ENCHANTMENT_RUNE, true)) { + if (!Slimefun.hasUnlocked(p, this, true)) { return true; } @@ -89,17 +87,14 @@ public class EnchantmentRune extends SimpleSlimefunItem { Item entity = (Item) optional.get(); ItemStack target = entity.getItemStack(); - List enchantmentSet = Arrays.asList(applicableEnchantments.getOrDefault(target.getType(), new Enchantment[0])); - if (enchantmentSet.size() == 0) return; + List enchantmentList = applicableEnchantments.getOrDefault(target.getType(), new ArrayList<>()); + if (enchantmentList.isEmpty()) return; //Removing the enchantments that the item already has from enchantmentSet - for (Enchantment enchantment : enchantmentSet) { - for (Enchantment itemEnchantment : target.getEnchantments().keySet()) { - if (enchantment == itemEnchantment) enchantmentSet.remove(enchantment); - } - } + enchantmentList.removeIf(enchantment -> target.getEnchantments().containsKey(enchantment)); + if (enchantmentList.isEmpty()) return; - Enchantment enchantment = enchantmentSet.get(ThreadLocalRandom.current().nextInt(enchantmentSet.size())); + Enchantment enchantment = enchantmentList.get(ThreadLocalRandom.current().nextInt(enchantmentList.size())); int level = 1; if (enchantment.getMaxLevel() != 1) { level = ThreadLocalRandom.current().nextInt(enchantment.getMaxLevel()) + 1; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java index d84a7b6f7..614548712 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java @@ -48,7 +48,7 @@ public class SoulboundRune extends SimpleSlimefunItem { return (e, p, item) -> { if (isItem(item.getItemStack())) { - if (!Slimefun.hasUnlocked(p, SlimefunItems.SOULBOUND_RUNE, true)) { + if (!Slimefun.hasUnlocked(p, this, true)) { return true; } From 28b5d545da8f958ceaa9949e5eef9a92564be3f2 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Mon, 29 Jun 2020 00:56:38 +0300 Subject: [PATCH 17/20] Did some requested change. --- .../slimefun4/implementation/items/magical/EnchantmentRune.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java index 65f22d345..e1ba3df4a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java @@ -87,7 +87,7 @@ public class EnchantmentRune extends SimpleSlimefunItem { Item entity = (Item) optional.get(); ItemStack target = entity.getItemStack(); - List enchantmentList = applicableEnchantments.getOrDefault(target.getType(), new ArrayList<>()); + List enchantmentList = new ArrayList<>(applicableEnchantments.getOrDefault(target.getType(), new ArrayList<>())); if (enchantmentList.isEmpty()) return; //Removing the enchantments that the item already has from enchantmentSet From 833b2d3943b1f843ab26b51bbf6d145f85951ec3 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Mon, 29 Jun 2020 01:11:01 +0300 Subject: [PATCH 18/20] Did another requested change. --- .../items/magical/EnchantmentRune.java | 13 +++++++++---- src/main/resources/languages/messages_en.yml | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java index e1ba3df4a..704b7bb30 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java @@ -88,11 +88,17 @@ public class EnchantmentRune extends SimpleSlimefunItem { ItemStack target = entity.getItemStack(); List enchantmentList = new ArrayList<>(applicableEnchantments.getOrDefault(target.getType(), new ArrayList<>())); - if (enchantmentList.isEmpty()) return; + if (enchantmentList.isEmpty()) { + SlimefunPlugin.getLocal().sendMessage(p, "messages.enchantment-rune.fail", true); + return; + } //Removing the enchantments that the item already has from enchantmentSet enchantmentList.removeIf(enchantment -> target.getEnchantments().containsKey(enchantment)); - if (enchantmentList.isEmpty()) return; + if (enchantmentList.isEmpty()) { + SlimefunPlugin.getLocal().sendMessage(p, "messages.enchantment-rune.no-enchantment", true); + return; + } Enchantment enchantment = enchantmentList.get(ThreadLocalRandom.current().nextInt(enchantmentList.size())); int level = 1; @@ -121,8 +127,7 @@ public class EnchantmentRune extends SimpleSlimefunItem { SlimefunPlugin.getLocal().sendMessage(p, "messages.enchantment-rune.success", true); } }, 10L); - } - else { + } else { SlimefunPlugin.getLocal().sendMessage(p, "messages.enchantment-rune.fail", true); } } diff --git a/src/main/resources/languages/messages_en.yml b/src/main/resources/languages/messages_en.yml index 504bad48a..df5a0f525 100644 --- a/src/main/resources/languages/messages_en.yml +++ b/src/main/resources/languages/messages_en.yml @@ -132,6 +132,7 @@ messages: enchantment-rune: fail: '&cYou cannot enchant this item.' + no-enchantment: '&cCouldn''t find any applicable enchantment for this item.' success: '&aYou have successfully applied a random applicable enchantment to this item.' research: From 942bf436bbbb934a7975eb923b604286f9458499 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Mon, 29 Jun 2020 10:02:54 +0300 Subject: [PATCH 19/20] Did another requested change. --- .../items/magical/EnchantmentRune.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java index 704b7bb30..5dfc4cba6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java @@ -3,6 +3,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.magical; import java.util.ArrayList; import java.util.Collection; import java.util.EnumMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Optional; @@ -87,20 +88,27 @@ public class EnchantmentRune extends SimpleSlimefunItem { Item entity = (Item) optional.get(); ItemStack target = entity.getItemStack(); - List enchantmentList = new ArrayList<>(applicableEnchantments.getOrDefault(target.getType(), new ArrayList<>())); - if (enchantmentList.isEmpty()) { + List applicableEnchantmentList = new ArrayList<>(applicableEnchantments.getOrDefault(target.getType(), new ArrayList<>())); + if (applicableEnchantmentList.isEmpty()) { SlimefunPlugin.getLocal().sendMessage(p, "messages.enchantment-rune.fail", true); return; } //Removing the enchantments that the item already has from enchantmentSet - enchantmentList.removeIf(enchantment -> target.getEnchantments().containsKey(enchantment)); - if (enchantmentList.isEmpty()) { + for (Enchantment itemEnchantment : target.getEnchantments().keySet()) { + for (Enchantment applicableEnchantment : applicableEnchantmentList) { + if (applicableEnchantment == itemEnchantment || applicableEnchantment.conflictsWith(itemEnchantment)) { + applicableEnchantmentList.remove(applicableEnchantment); + } + } + } + + if (applicableEnchantmentList.isEmpty()) { SlimefunPlugin.getLocal().sendMessage(p, "messages.enchantment-rune.no-enchantment", true); return; } - Enchantment enchantment = enchantmentList.get(ThreadLocalRandom.current().nextInt(enchantmentList.size())); + Enchantment enchantment = applicableEnchantmentList.get(ThreadLocalRandom.current().nextInt(applicableEnchantmentList.size())); int level = 1; if (enchantment.getMaxLevel() != 1) { level = ThreadLocalRandom.current().nextInt(enchantment.getMaxLevel()) + 1; From b6112e272867516383c48831fa1dd9990b45c97b Mon Sep 17 00:00:00 2001 From: LinoxGH <54643600+LinoxGH@users.noreply.github.com> Date: Mon, 29 Jun 2020 14:45:27 +0300 Subject: [PATCH 20/20] Did a requested change. --- .../implementation/items/magical/EnchantmentRune.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java index 5dfc4cba6..658a215b4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java @@ -88,10 +88,12 @@ public class EnchantmentRune extends SimpleSlimefunItem { Item entity = (Item) optional.get(); ItemStack target = entity.getItemStack(); - List applicableEnchantmentList = new ArrayList<>(applicableEnchantments.getOrDefault(target.getType(), new ArrayList<>())); - if (applicableEnchantmentList.isEmpty()) { + List applicableEnchantmentList = applicableEnchantments.get(target.getType()); + if (applicableEnchantmentList == null) { SlimefunPlugin.getLocal().sendMessage(p, "messages.enchantment-rune.fail", true); return; + } else { + applicableEnchantmentList = new ArrayList<>(applicableEnchantmentList); } //Removing the enchantments that the item already has from enchantmentSet