Search in sources :

Example 1 with ISecurityObject

use of mekanism.common.lib.security.ISecurityObject 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 ISecurityObject

use of mekanism.common.lib.security.ISecurityObject 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 3 with ISecurityObject

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

the class ItemBlockMachine method addDetails.

@Override
public void addDetails(@Nonnull ItemStack stack, World world, @Nonnull List<ITextComponent> tooltip, boolean advanced) {
    tooltip.add(OwnerDisplay.of(MekanismClient.tryGetClientPlayer(), getOwnerUUID(stack)).getTextComponent());
    if (Attribute.has(getBlock(), AttributeSecurity.class)) {
        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));
        }
    }
    if (Attribute.has(getBlock(), AttributeEnergy.class)) {
        StorageUtils.addStoredEnergy(stack, tooltip, false);
    }
    // TODO: Make this support "multiple" tanks, and probably expose the tank via capabilities
    FluidStack fluidStack = StorageUtils.getStoredFluidFromNBT(stack);
    if (!fluidStack.isEmpty()) {
        tooltip.add(MekanismLang.GENERIC_STORED_MB.translateColored(EnumColor.PINK, fluidStack, EnumColor.GRAY, TextUtils.format(fluidStack.getAmount())));
    }
    if (Attribute.has(getBlock(), AttributeInventory.class)) {
        tooltip.add(MekanismLang.HAS_INVENTORY.translateColored(EnumColor.AQUA, EnumColor.GRAY, YesNo.of(hasInventory(stack))));
    }
    if (Attribute.has(getBlock(), AttributeUpgradeSupport.class)) {
        MekanismUtils.addUpgradesToTooltip(stack, tooltip);
    }
}
Also used : ISecurityObject(mekanism.common.lib.security.ISecurityObject) FluidStack(net.minecraftforge.fluids.FluidStack)

Aggregations

ISecurityObject (mekanism.common.lib.security.ISecurityObject)3 IOwnerItem (mekanism.common.lib.security.IOwnerItem)2 UUID (java.util.UUID)1 ISecurityItem (mekanism.common.lib.security.ISecurityItem)1 ItemStack (net.minecraft.item.ItemStack)1 FluidStack (net.minecraftforge.fluids.FluidStack)1