Resolve head data to avoid ping png effects in the database.

This commit is contained in:
Olof Larsson 2015-05-15 23:46:38 +02:00
parent 7b9620d38b
commit ba361733b3
3 changed files with 56 additions and 8 deletions

View File

@ -15,6 +15,7 @@ import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import com.massivecraft.massivecore.Couple;
import com.massivecraft.massivecore.util.HeadUtil; import com.massivecraft.massivecore.util.HeadUtil;
import com.massivecraft.massivecore.xlib.gson.JsonArray; import com.massivecraft.massivecore.xlib.gson.JsonArray;
import com.massivecraft.massivecore.xlib.gson.JsonElement; import com.massivecraft.massivecore.xlib.gson.JsonElement;
@ -168,10 +169,12 @@ public class ItemStackAdapterInnerV1_8 extends ItemStackAdapterInnerV1_7
{ {
if ( ! meta.hasOwner()) return; if ( ! meta.hasOwner()) return;
String name = HeadUtil.getName(meta); // Resolve to avoid MStore sync bouncing.
if (name != null) json.addProperty(SKULL_OWNER, name); Couple<String, UUID> 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()); if (id != null) json.addProperty(SKULL_OWNER_ID, id.toString());
} }
else else
@ -186,6 +189,11 @@ public class ItemStackAdapterInnerV1_8 extends ItemStackAdapterInnerV1_7
element = json.get(SKULL_OWNER_ID); element = json.get(SKULL_OWNER_ID);
if (element != null) id = UUID.fromString(element.getAsString()); if (element != null) id = UUID.fromString(element.getAsString());
// Resolve to avoid MStore sync bouncing.
Couple<String, UUID> resolved = HeadUtil.resolve(name, id);
name = resolved.getFirst();
id = resolved.getSecond();
if (name != null || id != null) if (name != null || id != null)
{ {
HeadUtil.set(meta, name, id); HeadUtil.set(meta, name, id);

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import com.massivecraft.massivecore.Couple;
import com.massivecraft.massivecore.particleeffect.ReflectionUtils.PackageType; import com.massivecraft.massivecore.particleeffect.ReflectionUtils.PackageType;
public class HeadUtil public class HeadUtil
@ -38,7 +39,7 @@ public class HeadUtil
} }
// -------------------------------------------- // // -------------------------------------------- //
// GAME PROFILE SIMPLE // GAMEPROFILE: SIMPLE
// -------------------------------------------- // // -------------------------------------------- //
public static Object getGameProfile(SkullMeta meta) public static Object getGameProfile(SkullMeta meta)
@ -52,7 +53,7 @@ public class HeadUtil
} }
// -------------------------------------------- // // -------------------------------------------- //
// GET // GAMEPROFILE: GET
// -------------------------------------------- // // -------------------------------------------- //
public static String getGameProfileName(Object gameProfile) public static String getGameProfileName(Object gameProfile)
@ -66,7 +67,7 @@ public class HeadUtil
} }
// -------------------------------------------- // // -------------------------------------------- //
// SET // GAMEPROFILE: SET
// -------------------------------------------- // // -------------------------------------------- //
public static void setGameProfileName(Object gameProfile, String name) public static void setGameProfileName(Object gameProfile, String name)
@ -80,7 +81,7 @@ public class HeadUtil
} }
// -------------------------------------------- // // -------------------------------------------- //
// ASDF // SKULLMETA: RAW
// -------------------------------------------- // // -------------------------------------------- //
public static String getName(SkullMeta meta) public static String getName(SkullMeta meta)
@ -108,4 +109,38 @@ public class HeadUtil
setGameProfileId(gameProfile, id); setGameProfileId(gameProfile, id);
} }
// -------------------------------------------- //
// RESOLVE
// -------------------------------------------- //
// We resolve the locally best possible information using IdUtil.
public static Couple<String, UUID> 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<String, UUID>(retName, retId);
}
public static Couple<String, UUID> resolve(SkullMeta meta)
{
return resolve(getName(meta), getId(meta));
}
} }

View File

@ -290,6 +290,11 @@ public class InventoryUtil
// CLONE ITEMSTACKS/INVENTORY // CLONE ITEMSTACKS/INVENTORY
// -------------------------------------------- // // -------------------------------------------- //
public static ItemStack cloneItemStack(ItemStack itemStack)
{
return new ItemStack(itemStack);
}
public static ItemStack[] cloneItemStacks(ItemStack[] itemStacks) public static ItemStack[] cloneItemStacks(ItemStack[] itemStacks)
{ {
ItemStack[] ret = new ItemStack[itemStacks.length]; ItemStack[] ret = new ItemStack[itemStacks.length];
@ -297,7 +302,7 @@ public class InventoryUtil
{ {
ItemStack stack = itemStacks[i]; ItemStack stack = itemStacks[i];
if (stack == null) continue; if (stack == null) continue;
ret[i] = new ItemStack(itemStacks[i]); ret[i] = cloneItemStack(itemStacks[i]);
} }
return ret; return ret;
} }