9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-27 10:59:13 +00:00
This commit is contained in:
XiaoMoMi
2024-07-28 18:02:55 +08:00
parent 5526e8d930
commit eb9bfb528c
5 changed files with 45 additions and 10 deletions

View File

@@ -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"
);
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright (C) <2024> <XiaoMoMi>
*
* 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 <https://www.gnu.org/licenses/>.
*/
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);
}
}