diff --git a/src/com/massivecraft/massivecore/adapter/ItemStackAdapterInnerV1_8.java b/src/com/massivecraft/massivecore/adapter/ItemStackAdapterInnerV1_8.java index a0aef88b..ac0ae260 100644 --- a/src/com/massivecraft/massivecore/adapter/ItemStackAdapterInnerV1_8.java +++ b/src/com/massivecraft/massivecore/adapter/ItemStackAdapterInnerV1_8.java @@ -15,6 +15,7 @@ import org.bukkit.inventory.meta.BannerMeta; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.SkullMeta; +import com.massivecraft.massivecore.Couple; import com.massivecraft.massivecore.util.HeadUtil; import com.massivecraft.massivecore.xlib.gson.JsonArray; import com.massivecraft.massivecore.xlib.gson.JsonElement; @@ -168,10 +169,12 @@ public class ItemStackAdapterInnerV1_8 extends ItemStackAdapterInnerV1_7 { if ( ! meta.hasOwner()) return; - String name = HeadUtil.getName(meta); - if (name != null) json.addProperty(SKULL_OWNER, name); + // Resolve to avoid MStore sync bouncing. + Couple resolved = HeadUtil.resolve(meta); + String name = resolved.getFirst(); + UUID id = resolved.getSecond(); - UUID id = HeadUtil.getId(meta); + if (name != null) json.addProperty(SKULL_OWNER, name); if (id != null) json.addProperty(SKULL_OWNER_ID, id.toString()); } else @@ -186,6 +189,11 @@ public class ItemStackAdapterInnerV1_8 extends ItemStackAdapterInnerV1_7 element = json.get(SKULL_OWNER_ID); if (element != null) id = UUID.fromString(element.getAsString()); + // Resolve to avoid MStore sync bouncing. + Couple resolved = HeadUtil.resolve(name, id); + name = resolved.getFirst(); + id = resolved.getSecond(); + if (name != null || id != null) { HeadUtil.set(meta, name, id); diff --git a/src/com/massivecraft/massivecore/util/HeadUtil.java b/src/com/massivecraft/massivecore/util/HeadUtil.java index 7a611b19..dfbb145d 100644 --- a/src/com/massivecraft/massivecore/util/HeadUtil.java +++ b/src/com/massivecraft/massivecore/util/HeadUtil.java @@ -5,6 +5,7 @@ import java.util.UUID; import org.bukkit.inventory.meta.SkullMeta; +import com.massivecraft.massivecore.Couple; import com.massivecraft.massivecore.particleeffect.ReflectionUtils.PackageType; public class HeadUtil @@ -38,7 +39,7 @@ public class HeadUtil } // -------------------------------------------- // - // GAME PROFILE SIMPLE + // GAMEPROFILE: SIMPLE // -------------------------------------------- // public static Object getGameProfile(SkullMeta meta) @@ -52,7 +53,7 @@ public class HeadUtil } // -------------------------------------------- // - // GET + // GAMEPROFILE: GET // -------------------------------------------- // public static String getGameProfileName(Object gameProfile) @@ -66,7 +67,7 @@ public class HeadUtil } // -------------------------------------------- // - // SET + // GAMEPROFILE: SET // -------------------------------------------- // public static void setGameProfileName(Object gameProfile, String name) @@ -80,7 +81,7 @@ public class HeadUtil } // -------------------------------------------- // - // ASDF + // SKULLMETA: RAW // -------------------------------------------- // public static String getName(SkullMeta meta) @@ -108,4 +109,38 @@ public class HeadUtil setGameProfileId(gameProfile, id); } + // -------------------------------------------- // + // RESOLVE + // -------------------------------------------- // + // We resolve the locally best possible information using IdUtil. + + public static Couple resolve(String name, UUID id) + { + // Create Ret + // We default to the input. + String retName = name; + UUID retId = id; + + // Fetch IdData + // First by name then id. + IdData data = null; + if (name != null) data = IdUtil.getNameToData().get(name); + if (data == null && id != null) data = IdUtil.getIdToData().get(id.toString()); + + // Use that data if found + if (data != null) + { + retName = data.getName(); + retId = MUtil.asUuid(data.getId()); + } + + // Return Ret + return new Couple(retName, retId); + } + + public static Couple resolve(SkullMeta meta) + { + return resolve(getName(meta), getId(meta)); + } + } diff --git a/src/com/massivecraft/massivecore/util/InventoryUtil.java b/src/com/massivecraft/massivecore/util/InventoryUtil.java index 8463c5cd..2b5ea6ee 100644 --- a/src/com/massivecraft/massivecore/util/InventoryUtil.java +++ b/src/com/massivecraft/massivecore/util/InventoryUtil.java @@ -290,6 +290,11 @@ public class InventoryUtil // CLONE ITEMSTACKS/INVENTORY // -------------------------------------------- // + public static ItemStack cloneItemStack(ItemStack itemStack) + { + return new ItemStack(itemStack); + } + public static ItemStack[] cloneItemStacks(ItemStack[] itemStacks) { ItemStack[] ret = new ItemStack[itemStacks.length]; @@ -297,7 +302,7 @@ public class InventoryUtil { ItemStack stack = itemStacks[i]; if (stack == null) continue; - ret[i] = new ItemStack(itemStacks[i]); + ret[i] = cloneItemStack(itemStacks[i]); } return ret; }