diff options
author | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-10-11 15:10:56 -0400 |
---|---|---|
committer | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-10-11 16:16:34 -0400 |
commit | 4fbcf1b2a4790f3033e97c55cab344abdfaea8d2 (patch) | |
tree | b2bdbb1bc96655191a4b8de9df6b2e28c18ef376 /src/main | |
parent | e4a8417403e2e4b32c76199b951d49a6244e4881 (diff) | |
download | Skyblocker-4fbcf1b2a4790f3033e97c55cab344abdfaea8d2.tar.gz Skyblocker-4fbcf1b2a4790f3033e97c55cab344abdfaea8d2.tar.bz2 Skyblocker-4fbcf1b2a4790f3033e97c55cab344abdfaea8d2.zip |
Remove optionals
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/item/CustomArmorDyeColors.java | 38 | ||||
-rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/ItemUtils.java | 14 |
2 files changed, 30 insertions, 22 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/CustomArmorDyeColors.java b/src/main/java/de/hysky/skyblocker/skyblock/item/CustomArmorDyeColors.java index 8fba8df8..1496c90f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/CustomArmorDyeColors.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/CustomArmorDyeColors.java @@ -40,27 +40,27 @@ public class CustomArmorDyeColors { if (Utils.isOnSkyblock() && heldItem != null) { if (heldItem.getItem() instanceof DyeableItem) { - String itemUuid = ItemUtils.getItemUuid(heldItem); + String itemUuid = ItemUtils.getItemUuid(heldItem); - if (!itemUuid.isEmpty()) { - Object2IntOpenHashMap<String> customDyeColors = SkyblockerConfigManager.get().general.customDyeColors; + if (!itemUuid.isEmpty()) { + Object2IntOpenHashMap<String> customDyeColors = SkyblockerConfigManager.get().general.customDyeColors; - if (hex == null) { - if (customDyeColors.containsKey(itemUuid)) { - customDyeColors.removeInt(itemUuid); - SkyblockerConfigManager.save(); - source.sendFeedback(Text.translatable("skyblocker.customDyeColors.removed")); - } else { - source.sendFeedback(Text.translatable("skyblocker.customDyeColors.neverHad")); - } - } else { - customDyeColors.put(itemUuid, Integer.decode("0x" + hex.replace("#", "")).intValue()); - SkyblockerConfigManager.save(); - source.sendFeedback(Text.translatable("skyblocker.customDyeColors.added")); - } - } else { - source.sendError(Text.translatable("skyblocker.customDyeColors.noItemUuid")); - } + if (hex == null) { + if (customDyeColors.containsKey(itemUuid)) { + customDyeColors.removeInt(itemUuid); + SkyblockerConfigManager.save(); + source.sendFeedback(Text.translatable("skyblocker.customDyeColors.removed")); + } else { + source.sendFeedback(Text.translatable("skyblocker.customDyeColors.neverHad")); + } + } else { + customDyeColors.put(itemUuid, Integer.decode("0x" + hex.replace("#", "")).intValue()); + SkyblockerConfigManager.save(); + source.sendFeedback(Text.translatable("skyblocker.customDyeColors.added")); + } + } else { + source.sendError(Text.translatable("skyblocker.customDyeColors.noItemUuid")); + } } else { source.sendError(Text.translatable("skyblocker.customDyeColors.notDyeable")); return Command.SINGLE_SUCCESS; diff --git a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java index ea861a88..fa04acf8 100644 --- a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java +++ b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java @@ -44,6 +44,7 @@ public class ItemUtils { /** * Gets the {@code ExtraAttributes} NBT tag from the item stack. + * * @param stack the item stack to get the {@code ExtraAttributes} NBT tag from * @return an optional containing the {@code ExtraAttributes} NBT tag of the item stack */ @@ -53,16 +54,18 @@ public class ItemUtils { /** * Gets the {@code ExtraAttributes} NBT tag from the item stack. + * * @param stack the item stack to get the {@code ExtraAttributes} NBT tag from * @return the {@code ExtraAttributes} NBT tag of the item stack, or null if the item stack is null or does not have an {@code ExtraAttributes} NBT tag */ @Nullable public static NbtCompound getExtraAttributes(@NotNull ItemStack stack) { - return getExtraAttributesOptional(stack).orElse(null); + return stack.getSubNbt(EXTRA_ATTRIBUTES); } /** * Gets the internal name of the item stack from the {@code ExtraAttributes} NBT tag. + * * @param stack the item stack to get the internal name from * @return an optional containing the internal name of the item stack */ @@ -72,15 +75,18 @@ public class ItemUtils { /** * Gets the internal name of the item stack from the {@code ExtraAttributes} NBT tag. + * * @param stack the item stack to get the internal name from * @return the internal name of the item stack, or an empty string if the item stack is null or does not have an internal name */ public static String getItemId(@NotNull ItemStack stack) { - return getItemIdOptional(stack).orElse(""); + NbtCompound extraAttributes = getExtraAttributes(stack); + return extraAttributes != null ? extraAttributes.getString(ID) : ""; } /** * Gets the UUID of the item stack from the {@code ExtraAttributes} NBT tag. + * * @param stack the item stack to get the UUID from * @return an optional containing the UUID of the item stack */ @@ -90,11 +96,13 @@ public class ItemUtils { /** * Gets the UUID of the item stack from the {@code ExtraAttributes} NBT tag. + * * @param stack the item stack to get the UUID from * @return the UUID of the item stack, or null if the item stack is null or does not have a UUID */ public static String getItemUuid(@NotNull ItemStack stack) { - return getItemUuidOptional(stack).orElse(""); + NbtCompound extraAttributes = getExtraAttributes(stack); + return extraAttributes != null ? extraAttributes.getString(UUID) : ""; } @Nullable |