Skip to content

Commit

Permalink
Fixed hasCustomModelData NoSuchMethodError on legacy versions
Browse files Browse the repository at this point in the history
  • Loading branch information
LOOHP committed Jan 8, 2025
1 parent b783c98 commit 7007828
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

public class CustomModelData {

public static boolean isEmpty(CustomModelData data) {
return data == null || data.isEmpty();
}

private final List<Float> floats;
private final List<Boolean> flags;
private final List<String> strings;
Expand Down Expand Up @@ -84,4 +88,8 @@ public boolean hasLegacyIndex() {
public float getLegacyIndex() {
return floats.get(0);
}

public boolean isEmpty() {
return floats.isEmpty() && flags.isEmpty() && strings.isEmpty() && colors.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.loohp.interactivechatdiscordsrvaddon.debug.Debug;
import com.loohp.interactivechatdiscordsrvaddon.nms.NMSAddon;
import com.loohp.interactivechatdiscordsrvaddon.objectholders.AdvancementType;
import com.loohp.interactivechatdiscordsrvaddon.objectholders.CustomModelData;
import com.loohp.interactivechatdiscordsrvaddon.objectholders.PaintingVariant;
import com.loohp.interactivechatdiscordsrvaddon.objectholders.SteppedIntegerRange;
import com.loohp.interactivechatdiscordsrvaddon.objectholders.TintColorProvider;
Expand Down Expand Up @@ -281,7 +282,7 @@ public static BufferedImage getInventoryImage(Inventory inventory, Component tit
Debug.debug("ImageGeneration creating inventory image of " + player.getName());

String key = INVENTORY_CACHE_KEY + HashUtils.createSha1(title == null ? "Inventory" : InteractiveChatComponentSerializer.gson().serialize(title), inventory);
if (!inventory.contains(XMaterial.COMPASS.parseMaterial()) && !inventory.contains(XMaterial.CLOCK.parseMaterial()) && Arrays.stream(inventory.getContents()).noneMatch(each -> each != null && each.hasItemMeta() && each.getItemMeta().hasCustomModelData())) {
if (!inventory.contains(XMaterial.COMPASS.parseMaterial()) && !inventory.contains(XMaterial.CLOCK.parseMaterial()) && Arrays.stream(inventory.getContents()).noneMatch(each -> each != null && !CustomModelData.isEmpty(NMSAddon.getInstance().getCustomModelData(each)))) {
CacheObject<?> cache = resourceManager.get().getResourceRegistry(ICacheManager.IDENTIFIER, ICacheManager.class).getCache(key);
if (cache != null) {
return ImageUtils.copyImage((BufferedImage) cache.getObject());
Expand Down Expand Up @@ -345,7 +346,7 @@ public static BufferedImage getPlayerInventoryImage(Inventory inventory, ItemSta
}

String key = PLAYER_INVENTORY_CACHE_KEY + HashUtils.createSha1(player.isRightHanded(), player.getSelectedSlot(), 0, player.getUniqueId().toString(), inventory) + ImageUtils.hash(background);
if (!inventory.contains(XMaterial.COMPASS.parseMaterial()) && !inventory.contains(XMaterial.CLOCK.parseMaterial()) && Arrays.stream(inventory.getContents()).noneMatch(each -> each != null && each.hasItemMeta() && each.getItemMeta().hasCustomModelData())) {
if (!inventory.contains(XMaterial.COMPASS.parseMaterial()) && !inventory.contains(XMaterial.CLOCK.parseMaterial()) && Arrays.stream(inventory.getContents()).noneMatch(each -> each != null && !CustomModelData.isEmpty(NMSAddon.getInstance().getCustomModelData(each)))) {
CacheObject<?> cache = resourceManager.get().getResourceRegistry(ICacheManager.IDENTIFIER, ICacheManager.class).getCache(key);
if (cache != null) {
return ImageUtils.copyImage((BufferedImage) cache.getObject());
Expand Down

0 comments on commit 7007828

Please sign in to comment.