Potential fix for a bunch of stuff that required the use of UUID -> username lookup on servers. This fix adds an extra tag to the NBT of items so that it caches the username of the owner. The UUID is still stored on items, but is not used client-side.
This commit is contained in:
parent
14459ddc69
commit
ec7676a69c
|
@ -4,6 +4,7 @@ Version 2.0.0-5
|
|||
- Tweaked Sentient Sword's will drop rate
|
||||
- No longer 1.8.8 compatible
|
||||
- Cleaned some clutter from JEI
|
||||
- Added a potential fix to some server mod issues.
|
||||
|
||||
|
||||
------------------------------------------------------
|
||||
|
|
|
@ -9,6 +9,7 @@ public class Constants
|
|||
public static class NBT
|
||||
{
|
||||
public static final String OWNER_UUID = "ownerUUID";
|
||||
public static final String OWNER_NAME = "ownerNAME";
|
||||
public static final String USES = "uses";
|
||||
public static final String UNUSABLE = "unusable";
|
||||
public static final String SACRIFICE = "sacrifice";
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package WayofTime.bloodmagic.api.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.api.event.ItemBindEvent;
|
||||
import WayofTime.bloodmagic.api.iface.IBindable;
|
||||
import com.google.common.base.Strings;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import java.util.UUID;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.api.event.ItemBindEvent;
|
||||
import WayofTime.bloodmagic.api.iface.IBindable;
|
||||
|
||||
public class BindableHelper
|
||||
{
|
||||
|
@ -26,7 +25,7 @@ public class BindableHelper
|
|||
*/
|
||||
public static boolean checkAndSetItemOwner(ItemStack stack, EntityPlayer player)
|
||||
{
|
||||
return !PlayerHelper.isFakePlayer(player) && checkAndSetItemOwner(stack, PlayerHelper.getUUIDFromPlayer(player));
|
||||
return !PlayerHelper.isFakePlayer(player) && checkAndSetItemOwner(stack, PlayerHelper.getUUIDFromPlayer(player), player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,22 +40,30 @@ public class BindableHelper
|
|||
* - The ItemStack to bind
|
||||
* @param uuid
|
||||
* - The username to bind the ItemStack to
|
||||
* @param currentUsername
|
||||
* - The current name of the player.
|
||||
*
|
||||
* @return - Whether the binding was successful
|
||||
*/
|
||||
public static boolean checkAndSetItemOwner(ItemStack stack, String uuid)
|
||||
public static boolean checkAndSetItemOwner(ItemStack stack, String uuid, String currentUsername)
|
||||
{
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
|
||||
if (!(stack.getItem() instanceof IBindable))
|
||||
return false;
|
||||
|
||||
if (Strings.isNullOrEmpty(stack.getTagCompound().getString(Constants.NBT.OWNER_UUID)))
|
||||
String currentOwner = stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
|
||||
|
||||
if (currentOwner == "") //The player has not been set yet, so set everything.
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new ItemBindEvent(PlayerHelper.getPlayerFromUUID(uuid), uuid, stack));
|
||||
((IBindable) stack.getItem()).onBind(PlayerHelper.getPlayerFromUUID(uuid), stack);
|
||||
stack.getTagCompound().setString(Constants.NBT.OWNER_UUID, uuid);
|
||||
stack.getTagCompound().setString(Constants.NBT.OWNER_NAME, currentUsername);
|
||||
return true;
|
||||
} else if (currentOwner.equals(uuid)) //The player has been set, so this will simply update the display name
|
||||
{
|
||||
stack.getTagCompound().setString(Constants.NBT.OWNER_NAME, currentUsername);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -69,10 +76,12 @@ public class BindableHelper
|
|||
* - ItemStack to check
|
||||
* @param uuid
|
||||
* - UUID of the Player
|
||||
* @param currentUsername
|
||||
* - The current name of the player.
|
||||
*/
|
||||
public static boolean checkAndSetItemOwner(ItemStack stack, UUID uuid)
|
||||
public static boolean checkAndSetItemOwner(ItemStack stack, UUID uuid, String currentUsername)
|
||||
{
|
||||
return checkAndSetItemOwner(stack, uuid.toString());
|
||||
return checkAndSetItemOwner(stack, uuid.toString(), currentUsername);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,7 +23,7 @@ public class PlayerHelper
|
|||
|
||||
public static String getUsernameFromPlayer(EntityPlayer player)
|
||||
{
|
||||
return UsernameCache.getLastKnownUsername(getUUIDFromPlayer(player));
|
||||
return player.worldObj.isRemote ? "" : UsernameCache.getLastKnownUsername(getUUIDFromPlayer(player));
|
||||
}
|
||||
|
||||
public static EntityPlayer getPlayerFromUsername(String username)
|
||||
|
@ -63,16 +63,19 @@ public class PlayerHelper
|
|||
{
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
|
||||
return PlayerHelper.getUsernameFromUUID(stack.getTagCompound().getString(Constants.NBT.OWNER_UUID));
|
||||
return stack.getTagCompound().getString(Constants.NBT.OWNER_NAME);
|
||||
}
|
||||
|
||||
public static boolean isFakePlayer(EntityPlayer player)
|
||||
{
|
||||
return player != null && player instanceof FakePlayer || FAKE_PLAYER_PATTERN.matcher(getUsernameFromPlayer(player)).matches();
|
||||
return player != null && (player instanceof FakePlayer || FAKE_PLAYER_PATTERN.matcher(getUsernameFromPlayer(player)).matches());
|
||||
}
|
||||
|
||||
public static void causeNauseaToPlayer(ItemStack stack)
|
||||
{
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
|
||||
return;
|
||||
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
|
||||
if (!Strings.isNullOrEmpty(stack.getTagCompound().getString(Constants.NBT.OWNER_UUID)))
|
||||
|
|
|
@ -24,10 +24,6 @@ public class ItemSigilDivination extends ItemSigilBase implements IAltarReader
|
|||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||
{
|
||||
|
||||
if (PlayerHelper.isFakePlayer(player))
|
||||
return stack;
|
||||
|
||||
super.onItemRightClick(stack, world, player);
|
||||
|
||||
if (!world.isRemote)
|
||||
|
|
|
@ -25,10 +25,6 @@ public class ItemSigilSeer extends ItemSigilBase implements IAltarReader
|
|||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||
{
|
||||
|
||||
if (PlayerHelper.isFakePlayer(player))
|
||||
return stack;
|
||||
|
||||
super.onItemRightClick(stack, world, player);
|
||||
|
||||
if (!world.isRemote)
|
||||
|
|
Loading…
Reference in a new issue