Search in sources :

Example 1 with IOwnerItem

use of mekanism.common.lib.security.IOwnerItem in project Mekanism by mekanism.

the class SecurityUtils method canAccess.

public static boolean canAccess(PlayerEntity player, Object object) {
    ISecurityObject security;
    if (object instanceof ItemStack) {
        ItemStack stack = (ItemStack) object;
        if (!(stack.getItem() instanceof ISecurityItem) && stack.getItem() instanceof IOwnerItem) {
            // If it is an owner item but not a security item make sure the owner matches
            if (!MekanismConfig.general.allowProtection.get() || isOp(player)) {
                // If protection is disabled or the player is an op and bypass restrictions are enabled, access is always granted
                return true;
            }
            UUID owner = ((IOwnerItem) stack.getItem()).getOwnerUUID(stack);
            return owner == null || owner.equals(player.getUUID());
        }
        security = wrapSecurityItem(stack);
    } else if (object instanceof ISecurityObject) {
        security = (ISecurityObject) object;
    } else {
        // The object doesn't have security so there are no security restrictions
        return true;
    }
    return !security.hasSecurity() || canAccess(security.getSecurityMode(), player, security.getOwnerUUID());
}
Also used : ISecurityObject(mekanism.common.lib.security.ISecurityObject) ISecurityItem(mekanism.common.lib.security.ISecurityItem) IOwnerItem(mekanism.common.lib.security.IOwnerItem) ItemStack(net.minecraft.item.ItemStack) UUID(java.util.UUID)

Example 2 with IOwnerItem

use of mekanism.common.lib.security.IOwnerItem in project Mekanism by mekanism.

the class SecurityUtils method claimItem.

public static void claimItem(PlayerEntity player, ItemStack stack) {
    if (stack.getItem() instanceof IOwnerItem) {
        ((IOwnerItem) stack.getItem()).setOwnerUUID(stack, player.getUUID());
        Mekanism.packetHandler.sendToAll(new PacketSecurityUpdate(player.getUUID(), null));
        player.sendMessage(MekanismUtils.logFormat(MekanismLang.NOW_OWN), Util.NIL_UUID);
    }
}
Also used : IOwnerItem(mekanism.common.lib.security.IOwnerItem) PacketSecurityUpdate(mekanism.common.network.to_client.PacketSecurityUpdate)

Example 3 with IOwnerItem

use of mekanism.common.lib.security.IOwnerItem in project Mekanism by mekanism.

the class SecurityUtils method addSecurityTooltip.

/**
 * Only call this on the client
 */
public static void addSecurityTooltip(@Nonnull ItemStack stack, @Nonnull List<ITextComponent> tooltip) {
    if (stack.getItem() instanceof IOwnerItem) {
        tooltip.add(OwnerDisplay.of(MekanismClient.tryGetClientPlayer(), ((IOwnerItem) stack.getItem()).getOwnerUUID(stack)).getTextComponent());
    }
    ISecurityObject securityObject = SecurityUtils.wrapSecurityItem(stack);
    tooltip.add(MekanismLang.SECURITY.translateColored(EnumColor.GRAY, SecurityUtils.getSecurity(securityObject, Dist.CLIENT)));
    if (SecurityUtils.isOverridden(securityObject, Dist.CLIENT)) {
        tooltip.add(MekanismLang.SECURITY_OVERRIDDEN.translateColored(EnumColor.RED));
    }
}
Also used : ISecurityObject(mekanism.common.lib.security.ISecurityObject) IOwnerItem(mekanism.common.lib.security.IOwnerItem)

Example 4 with IOwnerItem

use of mekanism.common.lib.security.IOwnerItem in project Mekanism by mekanism.

the class SecurityInventorySlot method unlock.

public void unlock(UUID ownerUUID) {
    if (!isEmpty() && current.getItem() instanceof IOwnerItem) {
        IOwnerItem item = (IOwnerItem) current.getItem();
        UUID stackOwner = item.getOwnerUUID(current);
        if (stackOwner != null && stackOwner.equals(ownerUUID)) {
            item.setOwnerUUID(current, null);
            if (item instanceof ISecurityItem) {
                ((ISecurityItem) item).setSecurity(current, SecurityMode.PUBLIC);
            }
        }
    }
}
Also used : ISecurityItem(mekanism.common.lib.security.ISecurityItem) IOwnerItem(mekanism.common.lib.security.IOwnerItem) UUID(java.util.UUID)

Example 5 with IOwnerItem

use of mekanism.common.lib.security.IOwnerItem in project Mekanism by mekanism.

the class SecurityInventorySlot method lock.

public void lock(UUID ownerUUID, SecurityFrequency frequency) {
    if (!isEmpty() && current.getItem() instanceof IOwnerItem) {
        IOwnerItem item = (IOwnerItem) current.getItem();
        UUID stackOwner = item.getOwnerUUID(current);
        if (stackOwner == null) {
            item.setOwnerUUID(current, stackOwner = ownerUUID);
        }
        if (stackOwner.equals(ownerUUID)) {
            if (item instanceof ISecurityItem) {
                ((ISecurityItem) item).setSecurity(current, frequency.getSecurityMode());
            }
        }
    }
}
Also used : ISecurityItem(mekanism.common.lib.security.ISecurityItem) IOwnerItem(mekanism.common.lib.security.IOwnerItem) UUID(java.util.UUID)

Aggregations

IOwnerItem (mekanism.common.lib.security.IOwnerItem)5 UUID (java.util.UUID)3 ISecurityItem (mekanism.common.lib.security.ISecurityItem)3 ISecurityObject (mekanism.common.lib.security.ISecurityObject)2 PacketSecurityUpdate (mekanism.common.network.to_client.PacketSecurityUpdate)1 ItemStack (net.minecraft.item.ItemStack)1