From 1fdc955b39433b1e5ed5ffcfbb5859967f85a34c Mon Sep 17 00:00:00 2001 From: ProfElements Date: Tue, 21 Nov 2023 14:38:15 -0600 Subject: [PATCH 1/2] :bug: fix(#108): Align update info stack closer to `updateProgressbar`, should be a lot more performant --- .../electric/machines/MineralizedApiary.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/profelements/dynatech/items/electric/machines/MineralizedApiary.java b/src/main/java/me/profelements/dynatech/items/electric/machines/MineralizedApiary.java index aca66551..a4de6877 100644 --- a/src/main/java/me/profelements/dynatech/items/electric/machines/MineralizedApiary.java +++ b/src/main/java/me/profelements/dynatech/items/electric/machines/MineralizedApiary.java @@ -1,12 +1,14 @@ package me.profelements.dynatech.items.electric.machines; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.bukkit.Material; import org.bukkit.block.Beehive; import org.bukkit.block.Block; import org.bukkit.block.BlockState; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -138,13 +140,25 @@ public boolean isSynchronized() { return true; } - private void updateInfoStack(BlockMenu menu, int beeCount) { + private static void updateInfoStack(BlockMenu menu, int beeCount) { + Inventory inv = menu.toInventory(); + + if (inv == null || inv.getViewers().isEmpty()) { + return; + } + int currSpeed = 100; if (beeCount > 0) { currSpeed = 30 - ((beeCount - 1) * 10); } - ItemStack infoStack = new CustomItemStack(Material.BEACON, "&fINFO", "&fBee Count: " + String.valueOf(beeCount), "&fCurrent Speed: " + String.valueOf(currSpeed) + "s"); - menu.replaceExistingItem(20, infoStack); + ItemStack item = PROGRESS_STACK.clone(); + ItemMeta meta = item.getItemMeta(); + + meta.setDisplayName("&fInfo"); + meta.setLore(Arrays.asList("&fBee Count: " + String.valueOf(beeCount), "&fCurrent Speed: " + String.valueOf(currSpeed) + "s")); + item.setItemMeta(meta); + + menu.replaceExistingItem(20, item); } } From 71c0ffbe485b1132c68554c09ad59e1856dd3c77 Mon Sep 17 00:00:00 2001 From: ProfElements Date: Tue, 21 Nov 2023 14:43:30 -0600 Subject: [PATCH 2/2] :art: chore: Clean up code smells --- .../dynatech/items/electric/machines/MineralizedApiary.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/profelements/dynatech/items/electric/machines/MineralizedApiary.java b/src/main/java/me/profelements/dynatech/items/electric/machines/MineralizedApiary.java index a4de6877..7e7e62ce 100644 --- a/src/main/java/me/profelements/dynatech/items/electric/machines/MineralizedApiary.java +++ b/src/main/java/me/profelements/dynatech/items/electric/machines/MineralizedApiary.java @@ -156,7 +156,7 @@ private static void updateInfoStack(BlockMenu menu, int beeCount) { ItemMeta meta = item.getItemMeta(); meta.setDisplayName("&fInfo"); - meta.setLore(Arrays.asList("&fBee Count: " + String.valueOf(beeCount), "&fCurrent Speed: " + String.valueOf(currSpeed) + "s")); + meta.setLore(Arrays.asList("&fBee Count: " + beeCount, "&fCurrent Speed: " + currSpeed + "s")); item.setItemMeta(meta); menu.replaceExistingItem(20, item);