diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/FishingStatistics.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/FishingStatistics.java index c07df8aa..374c0ecb 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/FishingStatistics.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/FishingStatistics.java @@ -45,7 +45,7 @@ public interface FishingStatistics { * Retrieves the amount of fish caught with the specified ID. * * @param id the ID of the fish. - * @return the amount of fish caught with the specified ID. -1 if not exist. + * @return the amount of fish caught with the specified ID. 0 if not exist. */ int getAmount(String id); diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/FishingStatisticsImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/FishingStatisticsImpl.java index d6a8a5fa..a12386f7 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/FishingStatisticsImpl.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/FishingStatisticsImpl.java @@ -47,7 +47,7 @@ public class FishingStatisticsImpl implements FishingStatistics { @Override public int getAmount(String id) { - return amountMap.getOrDefault(id, -1); + return amountMap.getOrDefault(id, 0); } @Override @@ -70,12 +70,12 @@ public class FishingStatisticsImpl implements FishingStatistics { @Override public float getMaxSize(String id) { - return sizeMap.getOrDefault(id, -1f); + return sizeMap.getOrDefault(id, 0f); } @Override public void setMaxSize(String id, float maxSize) { - if (maxSize < 0) maxSize = 0; + if (maxSize < 0) return; sizeMap.put(id, maxSize); } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/item/impl/UniversalItemFactory.java b/core/src/main/java/net/momirealms/customfishing/bukkit/item/impl/UniversalItemFactory.java index e30998e8..80c1a526 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/item/impl/UniversalItemFactory.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/item/impl/UniversalItemFactory.java @@ -22,14 +22,13 @@ import com.saicone.rtag.tag.TagBase; import com.saicone.rtag.tag.TagCompound; import com.saicone.rtag.tag.TagList; import net.momirealms.customfishing.bukkit.item.BukkitItemFactory; +import net.momirealms.customfishing.bukkit.util.SkullUtils; import net.momirealms.customfishing.common.plugin.CustomFishingPlugin; import net.momirealms.customfishing.common.util.Key; import org.bukkit.inventory.ItemFlag; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.nio.charset.StandardCharsets; +import java.util.*; public class UniversalItemFactory extends BukkitItemFactory { @@ -72,7 +71,11 @@ public class UniversalItemFactory extends BukkitItemFactory { if (skullData == null) { item.remove("SkullOwner"); } else { - item.set(List.of(Map.of("Value", skullData)), "SkullOwner", "Properties", "textures"); + item.set(UUID.nameUUIDFromBytes(SkullUtils.identifierFromBase64(skullData).getBytes(StandardCharsets.UTF_8)), "SkullOwner", "Id"); + item.set( + List.of(Map.of("Value", skullData)), + "SkullOwner", "Properties", "textures" + ); } } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/util/SkullUtils.java b/core/src/main/java/net/momirealms/customfishing/bukkit/util/SkullUtils.java new file mode 100644 index 00000000..2c048c19 --- /dev/null +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/util/SkullUtils.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) <2024> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customfishing.bukkit.util; + +import java.util.Base64; + +public class SkullUtils { + + public static String identifierFromBase64(String base64) { + byte[] decodedBytes = Base64.getDecoder().decode(base64); + String decodedString = new String(decodedBytes); + int urlStartIndex = decodedString.indexOf("\"url\":\"") + 7; + int urlEndIndex = decodedString.indexOf("\"", urlStartIndex); + String textureUrl = decodedString.substring(urlStartIndex, urlEndIndex); + return textureUrl.substring(textureUrl.lastIndexOf('/') + 1); + } +} diff --git a/gradle.properties b/gradle.properties index 0336f7d3..a9710f2c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ # Project settings # Rule: [major update].[feature update].[bug fix] -project_version=2.2.8 +project_version=2.2.9 config_version=34 project_group=net.momirealms