Move getOwnerName/UUID to IBindable
Where it should have been to begin with... hehe... Deprecated methods will be removed after beta
This commit is contained in:
parent
8c1eaddb97
commit
fd16a58b6b
|
@ -3,11 +3,38 @@ package WayofTime.bloodmagic.api.iface;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement this interface on any Item that can be bound to a player.
|
* Implement this interface on any Item that can be bound to a player.
|
||||||
*/
|
*/
|
||||||
public interface IBindable
|
public interface IBindable
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Gets the username of the Item's owner. Usually for display,
|
||||||
|
* such as in the tooltip.
|
||||||
|
*
|
||||||
|
* If the item is not bound, this will be null.
|
||||||
|
*
|
||||||
|
* @param stack
|
||||||
|
* - The owned ItemStack
|
||||||
|
*
|
||||||
|
* @return - The username of the Item's owner
|
||||||
|
*/
|
||||||
|
String getOwnerName(ItemStack stack);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the UUID of the Item's owner.
|
||||||
|
*
|
||||||
|
* If the item is not bound, this will be null.
|
||||||
|
*
|
||||||
|
* @param stack
|
||||||
|
* - The owned ItemStack
|
||||||
|
*
|
||||||
|
* @return - The UUID of the Item's owner
|
||||||
|
*/
|
||||||
|
String getOwnerUUID(ItemStack stack);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the player attempts to bind the item.
|
* Called when the player attempts to bind the item.
|
||||||
*
|
*
|
||||||
|
|
|
@ -44,14 +44,19 @@ public class BindableHelper
|
||||||
stack.getTagCompound().setString(Constants.NBT.OWNER_UUID, ownerUUID);
|
stack.getTagCompound().setString(Constants.NBT.OWNER_UUID, ownerUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Everything below is to be removed.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to safely obtain the username of the ItemStack's owner
|
* Deprecated.
|
||||||
|
*
|
||||||
|
* Built into {@link IBindable} now.
|
||||||
*
|
*
|
||||||
* @param stack
|
* @param stack
|
||||||
* - The ItemStack to check the owner of
|
* - The ItemStack to check the owner of
|
||||||
*
|
*
|
||||||
* @return - The username of the ItemStack's owner
|
* @return - The username of the ItemStack's owner
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static String getOwnerName(ItemStack stack)
|
public static String getOwnerName(ItemStack stack)
|
||||||
{
|
{
|
||||||
stack = NBTHelper.checkNBT(stack);
|
stack = NBTHelper.checkNBT(stack);
|
||||||
|
@ -60,13 +65,16 @@ public class BindableHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to safely obtain the UUID of the ItemStack's owner
|
* Deprecated.
|
||||||
|
*
|
||||||
|
* Built into {@link IBindable} now.
|
||||||
*
|
*
|
||||||
* @param stack
|
* @param stack
|
||||||
* - The ItemStack to check the owner of
|
* - The ItemStack to check the owner of
|
||||||
*
|
*
|
||||||
* @return - The UUID of the ItemStack's owner
|
* @return - The UUID of the ItemStack's owner
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static String getOwnerUUID(ItemStack stack)
|
public static String getOwnerUUID(ItemStack stack)
|
||||||
{
|
{
|
||||||
stack = NBTHelper.checkNBT(stack);
|
stack = NBTHelper.checkNBT(stack);
|
||||||
|
@ -74,8 +82,6 @@ public class BindableHelper
|
||||||
return stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
|
return stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Everything below is to be removed.
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deprecated.
|
* Deprecated.
|
||||||
*
|
*
|
||||||
|
|
|
@ -178,4 +178,16 @@ public class ItemBindable extends Item implements IBindable
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getOwnerName(ItemStack stack)
|
||||||
|
{
|
||||||
|
return stack != null ? NBTHelper.checkNBT(stack).getTagCompound().getString(Constants.NBT.OWNER_NAME) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getOwnerUUID(ItemStack stack)
|
||||||
|
{
|
||||||
|
return stack != null ? NBTHelper.checkNBT(stack).getTagCompound().getString(Constants.NBT.OWNER_UUID) : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,4 +80,16 @@ public class ItemBoundSword extends ItemSword implements IBindable
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getOwnerName(ItemStack stack)
|
||||||
|
{
|
||||||
|
return stack != null ? NBTHelper.checkNBT(stack).getTagCompound().getString(Constants.NBT.OWNER_NAME) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getOwnerUUID(ItemStack stack)
|
||||||
|
{
|
||||||
|
return stack != null ? NBTHelper.checkNBT(stack).getTagCompound().getString(Constants.NBT.OWNER_UUID) : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class ItemSigilDivination extends ItemSigilBase implements IAltarReader
|
||||||
if (!world.isRemote)
|
if (!world.isRemote)
|
||||||
{
|
{
|
||||||
MovingObjectPosition position = getMovingObjectPositionFromPlayer(world, player, false);
|
MovingObjectPosition position = getMovingObjectPositionFromPlayer(world, player, false);
|
||||||
int currentEssence = NetworkHelper.getSoulNetwork(BindableHelper.getOwnerUUID(stack)).getCurrentEssence();
|
int currentEssence = NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).getCurrentEssence();
|
||||||
|
|
||||||
if (position == null)
|
if (position == null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class ItemSigilSeer extends ItemSigilBase implements IAltarReader
|
||||||
if (!world.isRemote)
|
if (!world.isRemote)
|
||||||
{
|
{
|
||||||
MovingObjectPosition position = getMovingObjectPositionFromPlayer(world, player, false);
|
MovingObjectPosition position = getMovingObjectPositionFromPlayer(world, player, false);
|
||||||
int currentEssence = NetworkHelper.getSoulNetwork(BindableHelper.getOwnerUUID(stack)).getCurrentEssence();
|
int currentEssence = NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).getCurrentEssence();
|
||||||
|
|
||||||
if (position == null)
|
if (position == null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -61,8 +61,12 @@ public class RitualExpulsion extends Ritual
|
||||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||||
{
|
{
|
||||||
ItemStack itemStack = inventory.getStackInSlot(i);
|
ItemStack itemStack = inventory.getStackInSlot(i);
|
||||||
if (itemStack != null && itemStack.getItem() instanceof IBindable && !Strings.isNullOrEmpty(BindableHelper.getOwnerName(itemStack)) && !allowedNames.contains(BindableHelper.getOwnerName(itemStack)))
|
if (itemStack != null && itemStack.getItem() instanceof IBindable)
|
||||||
allowedNames.add(BindableHelper.getOwnerName(itemStack));
|
{
|
||||||
|
IBindable bindable = (IBindable) itemStack.getItem();
|
||||||
|
if (!Strings.isNullOrEmpty(bindable.getOwnerName(itemStack)) && !allowedNames.contains(bindable.getOwnerName(itemStack)))
|
||||||
|
allowedNames.add(bindable.getOwnerName(itemStack));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -205,9 +205,9 @@ public class EventHandler
|
||||||
if (held != null && held.getItem() instanceof IBindable)
|
if (held != null && held.getItem() instanceof IBindable)
|
||||||
{
|
{
|
||||||
held = NBTHelper.checkNBT(held);
|
held = NBTHelper.checkNBT(held);
|
||||||
if (Strings.isNullOrEmpty(BindableHelper.getOwnerUUID(held)))
|
|
||||||
{
|
|
||||||
IBindable bindable = (IBindable) held.getItem();
|
IBindable bindable = (IBindable) held.getItem();
|
||||||
|
if (Strings.isNullOrEmpty(bindable.getOwnerUUID(held)))
|
||||||
|
{
|
||||||
if (bindable.onBind(player, held))
|
if (bindable.onBind(player, held))
|
||||||
{
|
{
|
||||||
String uuid = PlayerHelper.getUUIDFromPlayer(player).toString();
|
String uuid = PlayerHelper.getUUIDFromPlayer(player).toString();
|
||||||
|
@ -218,7 +218,7 @@ public class EventHandler
|
||||||
BindableHelper.setItemOwnerUUID(held, uuid);
|
BindableHelper.setItemOwnerUUID(held, uuid);
|
||||||
BindableHelper.setItemOwnerName(held, player.getDisplayNameString());
|
BindableHelper.setItemOwnerName(held, player.getDisplayNameString());
|
||||||
}
|
}
|
||||||
} else if (BindableHelper.getOwnerUUID(held).equals(PlayerHelper.getUUIDFromPlayer(player).toString()) && !BindableHelper.getOwnerName(held).equals(player.getDisplayNameString()))
|
} else if (bindable.getOwnerUUID(held).equals(PlayerHelper.getUUIDFromPlayer(player).toString()) && !bindable.getOwnerName(held).equals(player.getDisplayNameString()))
|
||||||
BindableHelper.setItemOwnerName(held, player.getDisplayNameString());
|
BindableHelper.setItemOwnerName(held, player.getDisplayNameString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue