From 75c345483d838e6f74436b4fed305d6391cff426 Mon Sep 17 00:00:00 2001 From: Roch Blonndiaux Date: Sat, 25 Mar 2023 14:58:48 +0100 Subject: [PATCH] Optimization --- .../mmoitems/api/interaction/ItemSkin.java | 39 ++++--------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/ItemSkin.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/ItemSkin.java index b634ca10..8adb585d 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/ItemSkin.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/ItemSkin.java @@ -40,26 +40,13 @@ public class ItemSkin extends UseItem { return new ApplyResult(ResultType.NONE); } - boolean compatible = false; - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Applying onto " + MMOUtils.getDisplayName(target.getItem())); // Types compatibility check if (getMMOItem().hasData(ItemStats.COMPATIBLE_TYPES)) { //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that TYPE is compatible: "); - List acceptedTypes = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_TYPES)).getList(); - for (String type : acceptedTypes) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7e >\u00a7f " + type); - - if (type.equalsIgnoreCase(targetType.getId())) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7a Matched"); - compatible = true; - break; - } - } - - if (!compatible && acceptedTypes.size() > 0) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7c Incompatible"); + final List acceptedTypes = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_TYPES)).getList(); + if (acceptedTypes.stream().noneMatch(s -> s.equalsIgnoreCase(targetType.getId()))) { player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2); Message.SKIN_INCOMPATIBLE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem())) .send(player); @@ -70,22 +57,11 @@ public class ItemSkin extends UseItem { // IDs compatibility check if (getMMOItem().hasData(ItemStats.COMPATIBLE_IDS)) { //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that ID is compatible: "); + final List acceptedIDs = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_IDS)).getList(); + final String targetId = target.getString("MMOITEMS_ITEM_ID"); - List acceptedIDs = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_IDS)).getList(); - - for (String id : acceptedIDs) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a76 >\u00a7f " + id); - - if (id.equalsIgnoreCase(target.getString("MMOITEMS_ITEM_ID"))) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7a Matched"); - compatible = true; - break; - } - } - - if (!compatible && acceptedIDs.size() > 0) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7c Incompatible"); - + if (acceptedIDs.stream() + .noneMatch(s -> s.equalsIgnoreCase(targetId))) { player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2); Message.SKIN_INCOMPATIBLE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem())) .send(player); @@ -95,8 +71,7 @@ public class ItemSkin extends UseItem { // Material compatibility check if (getMMOItem().hasData(ItemStats.COMPATIBLE_MATERIALS)) { - //SKIN// - MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that MATERIAL is compatible: "); + //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that MATERIAL is compatible: "); List acceptedMaterials = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_MATERIALS)).getList(); if (acceptedMaterials.stream()