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());
}
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));
}
}
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);
}
}
Aggregations