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