public boolean isSecured() { return !SecurityHelper.isDefaultUUID(owner.getId()); }
@Override public boolean setOwner(GameProfile profile) { if (owner != CoreProps.DEFAULT_OWNER) { return false; } if (SecurityHelper.isDefaultUUID(owner.getId())) { owner = profile; if (!SecurityHelper.isDefaultUUID(owner.getId())) { if (FMLCommonHandler.instance().getMinecraftServerInstance() != null) { new Thread("CoFH User Loader") { @Override public void run() { owner = SecurityHelper.getProfile(owner.getId(), owner.getName()); } }.start(); } if (world != null) { markChunkDirty(); sendTilePacket(Side.CLIENT); } return true; } } return false; }
public boolean canPlayerAccess(EntityPlayer player) { if (!(this instanceof ISecurable)) { return true; } ISecurable.AccessMode access = ((ISecurable) this).getAccess(); String name = player.getName(); if (access.isPublic() || (CoreProps.enableOpSecureAccess && CoreUtils.isOp(name))) { return true; } GameProfile profile = ((ISecurable) this).getOwner(); UUID ownerID = profile.getId(); if (SecurityHelper.isDefaultUUID(ownerID)) { return true; } UUID otherID = SecurityHelper.getID(player); if (ownerID.equals(otherID)) { return true; } return access.isFriendsOnly() && RegistrySocial.playerHasAccess(name, profile); }
public static boolean canPlayerAccess(ItemStack stack, EntityPlayer player) { if (!SecurityHelper.isSecure(stack)) { return true; } String name = player.getName(); AccessMode access = SecurityHelper.getAccess(stack); if (access.isPublic() || (CoreProps.enableOpSecureAccess && CoreUtils.isOp(name))) { return true; } GameProfile profile = SecurityHelper.getOwner(stack); UUID ownerID = profile.getId(); if (SecurityHelper.isDefaultUUID(ownerID)) { return true; } UUID otherID = SecurityHelper.getID(player); return ownerID.equals(otherID) || access.isFriendsOnly() && RegistrySocial.playerHasAccess(name, profile); }
@Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); if (CoreUtils.isFakePlayer(player) || hand != EnumHand.MAIN_HAND) { return new ActionResult<>(EnumActionResult.FAIL, stack); } if (needsTag(stack)) { setDefaultInventoryTag(stack); } if (ServerHelper.isServerWorld(world)) { if (SecurityHelper.isSecure(stack) && SecurityHelper.isDefaultUUID(SecurityHelper.getOwner(stack).getId())) { SecurityHelper.setOwner(stack, player.getGameProfile()); ChatHelper.sendIndexedChatMessageToPlayer(player, new TextComponentTranslation("chat.cofh.secure.item.success")); return new ActionResult<>(EnumActionResult.SUCCESS, stack); } if (canPlayerAccess(stack, player)) { if (player.isSneaking() && ItemHelper.getItemDamage(stack) != CREATIVE) { player.openGui(ThermalExpansion.instance, GuiHandler.SATCHEL_FILTER_ID, world, 0, 0, 0); } else { player.openGui(ThermalExpansion.instance, GuiHandler.SATCHEL_ID, world, 0, 0, 0); } } else if (SecurityHelper.isSecure(stack)) { ChatHelper.sendIndexedChatMessageToPlayer(player, new TextComponentTranslation("chat.cofh.secure.warning", SecurityHelper.getOwnerName(stack))); return new ActionResult<>(EnumActionResult.FAIL, stack); } } return new ActionResult<>(EnumActionResult.SUCCESS, stack); }